我在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时,输出不会改变。
答案 0 :(得分: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 + "!";
}
}