我正在编写一个tamagotci风格的游戏,我需要每秒健康一次。我已经有一个得分号码,当你喂食目标时会改变它。如果有人能帮我编辑我目前的代码,每秒钟减少1点生命值,我将非常感激。这是我的代码,如果有人需要看到它;
health=100
txtform.font = "Arial";
txtform.color = 0x000000;
txtform.size = 24;
txtform.bold = true;
healthdisplay.defaultTextFormat=txtform;
addChild(healthdisplay);
healthdisplay.text=("Health: " + health)
healthdisplay.x=75
healthdisplay.y=-20
healthdisplay.autoSize=TextFieldAutoSize.CENTER;
}
public function IncreaseHealth(points:int){
health+=points
healthdisplay.text=("Health: " + health)
healthdisplay.defaultTextFormat=txtform;
}
答案 0 :(得分:0)
创建一个你每秒呼叫的函数DecreaseHealth()
。类似的东西:
var timer:Timer = new Timer(1000); // 1 second = 1000 milliseconds.
timer.addEventListener(TimerEvent.TIMER, DecreaseHealth);
timer.start();
DecreaseHealth()
具有以下签名:
function DecreaseHealth(event:TimerEvent):void
{
health -= 1;
// Do printing or whatever else here.
}