Hello! So, I am using the guiNode (not using NiftyGUI), and I would like to create a “subclass” of it, so that I can remove only certain children of the GUI without having to call guiNode.detachAllChildren() and then adding all the relevant children again! Basically like switching between appstates… so, if this is possible, what type should this child be of? A new guiNode? Node?
(Some pseudocode if needed, the idea is clear in my head but I’m a bit tired so might not come out well)
[javan]
new Child1
new Child2
…
Attach all relevant pictures to each of the Children
…
if(playerWantsChild1) guiNode.attachChild(Child1)
if(playerWantsChild2) guiNode.attachChild(Child2)
if(playerWantstoKillChild1) guiNode.detachChild(Child1)
if(playerWantstoKillChild2) guiNode.detachChild(Child2)
[java]
new Child1
new Child2
…
Attach all relevant pictures to each of the Children
…
if(playerWantsChild1) guiNode.attachChild(Child1)
if(playerWantsChild2) guiNode.attachChild(Child2)
if(playerWantstoKillChild1) guiNode.detachChild(Child1)
if(playerWantstoKillChild2) guiNode.detachChild(Child2)[/java]
(my mistake, the code did not get this nifty code box, still new to this :-? )
@SCOMS said:
[java]
new Child1
new Child2
…
Attach all relevant pictures to each of the Children
…
if(playerWantsChild1) guiNode.attachChild(Child1)
if(playerWantsChild2) guiNode.attachChild(Child2)
if(playerWantstoKillChild1) guiNode.detachChild(Child1)
if(playerWantstoKillChild2) guiNode.detachChild(Child2)[/java]
(my mistake, the code did not get this nifty code box, still new to this :-? )
[java]
if (child1.getParent() != null)
child1.removeFromParent();
[/java]
@t0neg0d said:
[java]
if (child1.getParent() != null)
child1.removeFromParent();
[/java]
Will have the effect you are looking for.
All right, thanks a lot for all the helpful answers (only quoting yours but all of them are really helpful!). I guess I’ll have to rethink my strategy… but the reason why I wanted to be able to remove large “blocks” from the GUI - realising now I probably should have mentioned this - is in the event of having quite a few items on the screen, which could make removing the individual pieces quite clumsy and ugly.
I guess it could be thought of like appstates again… Let’s say I want to swap from “menu-input” to “game-input”. I wouldn’t like to manually overwrite each and every mapped key, but rather just put them all once in an appstate and activate that.