如何使用if语句删除if语句? AS3语句、如何使用、if

2023-09-09 21:40:58 作者:暮色浓妆ζ却微凉

我在做一个游戏,角色必须拿到钥匙后通过大门 所以当他得到密钥的门想走开,我用

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; }

但是,当他得到的关键是:这是

if(character.hitTestObject(key))
{
   gate.visible = false; }

现在,当我穿过大门,我明明再次获得被杀 现在我该怎样删除previous如果通过函数的下一个IF函数?

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;
    }
}
 
精彩推荐
图片推荐