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

时间:2014-08-19 07:06:47

标签: actionscript-3 if-statement flash-cs5 visible

我正在制作一个游戏,角色必须在获得钥匙后通过大门 因此,当他拿到钥匙时,大门就会消失,我用了

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

但是当他拿到钥匙时:它

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

当我穿过大门时,我显然会再次被杀 现在如何通过下一个if函数删除前一个if函数?

2 个答案:

答案 0 :(得分:3)

设置/检查布尔值。一个已存在于gate.visible

// If gate is visible and character hitTests gate then..
if(gate.visible && character.hitTestObject(gate)) {
    character.visible = false;                   
    youLose_text.visible = true; 
}

答案 1 :(得分:0)

如果门应该实际上消失了#34;你应该完全删除它,而不仅仅是让它看不见......例如:

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