0

大家好,我是动作脚本编程的新手,我找不到正确的方法。

我需要在这个游戏中有一个分数和计时器>>> http://www.filedropper.com/eggrun

它应该有用于添加分数的硬币和用于游戏时间的倒数计时器。

请帮帮我:(

我离做到这一点还差得很远。:(

4

1 回答 1

1

一些代码会有所帮助。但是要制作一个简单的倒数计时器,试试这个!我假设你在“时间轴”上编码

var count:Number = 60; //Count down from 60

var myTimer:Timer = new Timer(1000,count);// Timer intervall in ms

myTimer.addEventListener(TimerEvent.TIMER, countdown);//EventListener for intervalls
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, countdownComplete);
myTimer.start();//start Timer

function countdown(event:TimerEvent):void {
countDownTextField.text = String((count)-myTimer.currentCount); 
//Display Time in a textfield on stage, 
//i'll call it countDownTextField. U will have to create it first
}

function countdownComplete(event:TimerEvent):void {
   // fires when the countdown is finished
   removeEventListener(Event.ENTER_FRAME,onenter);//stops the game
   addChild(scoreScreen); //You have to create a Sprite or MovieClip with a TextField
   scoreScreen.scoreText.text = score.toString() // and then assign the score to the textField
//to start the game again just remove the scoreScreen and call the init() function
   myTimer.removeEventListener(TimerEvent.TIMER, countdown);//remove listers
   myTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, countdownComplete);

}

如果你需要一个定时器完成的方法,添加一个 TimerEvent.TIMER_COMPLETE 监听器!

请解释你的意思

它应该有用于添加分数的硬币

处理分数的最佳方法是使用函数

var score:int = 0;
function updateScore(addScore:int):void{
    score += addScore;

}

然后只要你需要像这样更新分数就调用它

updateScore(10);// adds 10 to the score
于 2013-02-23T13:10:22.537 回答