Many GUIs mounted to many objects
by Joe Rossi · in Torque Game Builder · 10/03/2006 (11:38 pm) · 5 replies
Small predicament here. I have a bunch of objects I'd like to mount health bars to ( progressbars ). I made a .gui file only containing one progressbar, and I'm calling %object.attachGui( healthbar , sceneWindow2D, 0 ); for each object. What's happening is, only the last object is getting a healthbar. Worse than that, each time I rerun the level more copies of that healthbar are created. Then TGB will crash. Any ideas?
#2
10/04/2006 (2:24 am)
You could programatically create a new health bar in script for each object and then attach it. As for changing the offset, there is unfortunately no way to specifically set it. You would have to manually move the gui control to the canvas position that corresponds to the world coordinates of the object in the scene window and then attach it. It's a little annoying, but worth it for the effect. You could also just make your health bars out of scene objects and forget the whole gui control thing alltogether.
#3
10/04/2006 (3:50 pm)
OK, I think I'm going to go the scene objects route.. that way I'll have more control and I can make them look cooler.. Thanks!
#4
10/04/2006 (4:11 pm)
I personally prefer that technique as well Joe, although until the t2dTextObject is built in to the next release, you will still want to use attached GUI's for pure text displays.
#5
I also have the problem you are reffering to with the health bars sticking around after returning to the editor, though I understand why its happening and know (for the most part) how to fix it. From what I gather, gui controls are not automatically deleted or disposed of when you return to the editor, and so when you 'run game' from within the editor, and it switches back to your games sceneGraph, the guicontrol is still around, right where it was when you went into the editor, though now you have no refference to it and no way to get rid of it.
**edit: hmm.. tried my own solution and it didn't work. :P Really, its just a matter of figuring out a callback that gets triggered when you hit stop and return to the editor, and using that opportunity to call delete() on any guicontrol's you may have created.
10/04/2006 (6:01 pm)
In a project i'm working on, I came across a similar need. My solution, based largely on the Strategy genre tutorial on TDN, was to create a dummy SceneObject, mount it to my units with a negative Y offset (so it appears above their heads), and then attach a dynamically created healthbar to this dummy sceneObject.I also have the problem you are reffering to with the health bars sticking around after returning to the editor, though I understand why its happening and know (for the most part) how to fix it. From what I gather, gui controls are not automatically deleted or disposed of when you return to the editor, and so when you 'run game' from within the editor, and it switches back to your games sceneGraph, the guicontrol is still around, right where it was when you went into the editor, though now you have no refference to it and no way to get rid of it.
**edit: hmm.. tried my own solution and it didn't work. :P Really, its just a matter of figuring out a callback that gets triggered when you hit stop and return to the editor, and using that opportunity to call delete() on any guicontrol's you may have created.
Torque Owner Joe Rossi
Indri Games
I also made sure to check if isobject(healthbar1) before I exec the .gui file, to be sure not to reload the guis.
If anyone has better ideas I'm open to suggestions..!
Another question... is there a way to attach guis to objects someplace other than their center? I tried to change the objects default link points away from the center, but that doesn't seem to help. Is there a way I can add some offset values?