Delete GUI Elements that still show after loadLevel?
by Joao Caxaria · in Technical Issues · 10/15/2008 (3:58 pm) · 4 replies
Hi,
I've added some GUI elements to my game by calling this:
Where the variable %this is a GUI element (for example a GuiTextCtrl to show the player score).
When the player loses/wins the level I take him to the summary of the level using the:
When I do this, all the GUI controls that I added before still show. I assumed (wrongly) that by loading a new level, everything on the screen would be scrapped.
My question is, how can I delete those GUI controls? Should I keep a SimSet with them all and just call delete in the end? Am I approaching the problem of showing player score, etc, in a wrong way by using the addGuiControl?
Thanks!
I've added some GUI elements to my game by calling this:
Canvas.getContent().addGuiControl(%this);
Where the variable %this is a GUI element (for example a GuiTextCtrl to show the player score).
When the player loses/wins the level I take him to the summary of the level using the:
sceneWindow2D.loadLevel("game/data/levels/summary.t2d");When I do this, all the GUI controls that I added before still show. I assumed (wrongly) that by loading a new level, everything on the screen would be scrapped.
My question is, how can I delete those GUI controls? Should I keep a SimSet with them all and just call delete in the end? Am I approaching the problem of showing player score, etc, in a wrong way by using the addGuiControl?
Thanks!
About the author
#2
If the game has a dynamic number of Gui's, are they stored somewhere inside the canvas object?
Thanks!
10/20/2008 (2:27 am)
Thanks Lee. How do you keep track of the visible GUI's? If the game has a dynamic number of Gui's, are they stored somewhere inside the canvas object?
Thanks!
#3
Other than that I'd say, "yeah, you better keep track of them" :-)
I'm not exactly sure how to answer your second question, and in fact I would not purport to be an expert, so if someone contradicts me on t his, I'm sure they're right. But my understanding is that gui objects exist just like other objects in the game, such as players and static shapes and stuff, and can be treated accordingly. More or less.
So a "dynamic number of gui's" implies that you'll be creating them and destroying them at will, which should be fine if I am correct. But I'm not sure if that's even meaningful. I'm not sure why you'd want to create the structure in-game. There's not a lot of memory at stake, so you just create your guis and make them visible as needed.
I'm a little fuzzy on a lot of that stuff, though. Feel free to check out my game, all the script source is shipped with it (in fact no dso's are shipped with it). Mind you I am not a programmer, so it's a bad example, but it may help to understand how they work, at least for me.
10/20/2008 (11:31 pm)
You can query them the same way to find out if they're visible or not. That's one way of tracking.Other than that I'd say, "yeah, you better keep track of them" :-)
I'm not exactly sure how to answer your second question, and in fact I would not purport to be an expert, so if someone contradicts me on t his, I'm sure they're right. But my understanding is that gui objects exist just like other objects in the game, such as players and static shapes and stuff, and can be treated accordingly. More or less.
So a "dynamic number of gui's" implies that you'll be creating them and destroying them at will, which should be fine if I am correct. But I'm not sure if that's even meaningful. I'm not sure why you'd want to create the structure in-game. There's not a lot of memory at stake, so you just create your guis and make them visible as needed.
I'm a little fuzzy on a lot of that stuff, though. Feel free to check out my game, all the script source is shipped with it (in fact no dso's are shipped with it). Mind you I am not a programmer, so it's a bad example, but it may help to understand how they work, at least for me.
#4
10/21/2008 (1:42 am)
Thanks Lee, I'll check it for sure :)
Torque Owner Lee Latham
Default Studio Name
GuiObjectName.visible = 0;
They should all have a member named "visible" that you can set to 0. At least that's how it is in TGE.
edit: Is "member" the correct term, here?