I'm making a game where the character has to pass through the gate after getting the key so when he gets the key the gate is suppose to go away, i used
if(character.hitTestObject(gate))
{character.visible = false;
youLose_text.visible = true; }
BUT when he gets the key: it's
if(character.hitTestObject(key))
{
gate.visible = false; }
NOW when i pass through the gate, i obviously get killed again now how do i remove the previous if function through the next if function?
If the gate is supposed to actually "go away", you should completely remove it, not just make it invisible... e.g.:
if(character.hitTestObject(key)) {
//don't forget to remove event listeners on the gate as well, if it had any
removeChild(gate);
gate = null;
} else if(gate != null) {
if(character.hitTestObject(gate)) {
character.visible = false;
youLose_text.visible = true;
}
}