0

我在 AS3 中制作了一个非常简单的 JRPG 战斗系统。我有一个名为输出的文本框,用于显示战斗事件。字体是嵌入的(我检查了十几次)。它是黑色背景上的白色文本。显示初始文本,但之后不会更新。我设置了代码来跟踪正在发生的事情,并且显示正确。我究竟做错了什么?谢谢。

这是代码(显然这不完整):

function BattleSystem():void
        {
            //add battle system event listeners
            stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown);
            stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);

            //initialize battle
            this.gotoAndStop(2);
            battleStart = true;
            playerAtks = false;
            output.text = ""
            output.text = "A dangerous " + _enemyName + " threatens to attack! What will you do? 1. Attack 2. Spells 3. Items ";


            function onKeyDown(event:KeyboardEvent):void
                {           

                    if (event.keyCode == Keyboard.NUMBER_1)
                    {
                        playerDmg = uint(_Str * ((Math.random() + 1)) - _enemyDef);
                    }
                }
            function onKeyUp(event:KeyboardEvent):void
            {
                if (event.keyCode == Keyboard.NUMBER_1)
                {
                    trace("You deal " + playerDmg + " damage to the " + _enemyName + "!")
                    output.text = "You deal " + playerDmg + " damage to the " + _enemyName + "!";
                }
            }
        }

例如,当前当我进入战斗时,输出显示“一个危险的史莱姆威胁要攻击!你会做什么?1.攻击 2.法术 3.物品”。但是当我点击 1 时,输出不会改变。

4

1 回答 1

0

您将事件处理程序封装在函数中,这是不对的。

尝试这个 :

function BattleSystem():void
{
     //add battle system event listeners
     stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown);
     stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);

     //initialize battle
     this.gotoAndStop(2);
     battleStart = true;
     playerAtks = false;
     output.text = ""
     output.text = "A dangerous " + _enemyName + " threatens to attack! What will you do? 1. Attack 2. Spells 3. Items ";

}

function onKeyDown(event:KeyboardEvent):void
{           

      if (event.keyCode == Keyboard.NUMBER_1)
      {
          playerDmg = uint(_Str * ((Math.random() + 1)) - _enemyDef);
      }
}

function onKeyUp(event:KeyboardEvent):void
{
    if (event.keyCode == Keyboard.NUMBER_1)
    {
         trace("You deal " + playerDmg + " damage to the " + _enemyName + "!")
         output.text = "You deal " + playerDmg + " damage to the " + _enemyName + "!";
     }
}
于 2013-04-20T17:32:22.457 回答