0

我在更新变量时遇到问题。下面,我的主文档函数的级别等于 1 并生成多个图块。它确实等于 1,但我有 if 语句说如果 var 等于 true,则上升一个级别。

    public var enemiesDefeated:Boolean = false;        
    addChild(level);
    //START THE GAME AT LEVEL 1//
    level.levelNumber = 1;
    if (enemiesDefeated == true){
        level.levelNumber += 1;
    }
    var tileh:int = 60;

    for (var Y:int=0; Y<floor.length; Y++)
    {
        for (var X:int=0; X<floor[Y].length; X++)
        {
                var cell:MovieClip = new Tile(X,Y);
            cell.gotoAndStop(floor[Y][X]);
            cell.x = ((X-Y)*tileh)+365;
            cell.y = ((X+Y)*tileh/2)+70;
            addChild(cell);

            cell.addEventListener(MouseEvent.CLICK, mouseclick);
            cell.addEventListener(Event.ENTER_FRAME, onGame);
            cell.addEventListener(Event.ADDED_TO_STAGE, addEnemy);
        }
    }

如果我摧毁所有敌人,我的 onGame 函数中的变量敌人Defeated 将变为 true,但是,在enemyDefeated 等于 true 之后,级别将保持在级别 1。

function onGame(event:Event){

    ...

    if (enemy.enemyHP <= 0) 
        {
             removeChild(enemy);
             enemy.enemyDead = true;
             enemiesDefeated = true;
             trace("Dead", enemy.enemyDead);
        }
}

有没有办法来解决这个问题?

4

0 回答 0