Can't remove elements from ig.gui?
Opened this issue · 0 comments
mccorkle commented
In my game, I'm trying to use ImpactJS-GUI to draw a pause menu / upgrade menu. It works like a champ on the first level, but once I jump to the second level, all of the upgrades are reset, but I can't figure out how to clear all the elements from my gui (since it isn't just killed by loadLevel).
Somehow, the following code ends up with at least 5 else conditions(meaning that I have elements that are undefined, but still affect the length of my elements array), and the final length of ig.gui.elements.length is still 5 after the loop.
Any idea what I'm doing wrong during my cleanup of the gui elements here?
if ( ig.gui.elements.length > 0 ) {
var myLength = ig.gui.elements.length;
for (var i = 0; i < myLength; i++) {
if ( typeof ig.gui.elements[i] != "undefined" ) {
ig.gui.element.action("remove", ig.gui.elements[i].name );
} else {
ig.log("tried to remove an undefined gui element" + i );
}
}
ig.log("already had gui elements, removed them." + ig.gui.elements.length);
}