所以我創造一個遊戲,我想添加的是一個不斷增加的計數器,直到玩家輸掉比賽。Flash遊戲得分不起作用AS3,請幫忙?
創建我的分數類,它看起來像這樣:
package
{
import flash.display.MovieClip;
import flash.display.Stage;
import flash.text.TextField;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class Score extends MovieClip
{
public var second:Number = 0;
public var timer:Timer = new Timer(10);
private var stageRef:Stage;
public function Score(stageRef:Stage)
{
x = 537.95;
y = 31.35;
this.stageRef = stageRef;
timer.addEventListener(TimerEvent.TIMER, clock);
timer.start();
}
function clock(evt:TimerEvent):void
{
second += 1;
scoreDisplay.text = String("Score: " +second);
}
}
}
,這是我的引擎類,它添加到舞臺:
package {
//list of our imports these are classes we need in order to
//run our application.
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
public class Engine extends MovieClip{
private var enemyList:Array = new Array();
private var ourBoat:Boat;
private var score:Score;
public function Engine() : void{
//create an object of our ship from the Ship class
ourBoat = new Boat(stage);
score = new Score(stage);
//add it to the display list
stage.addChild(ourBoat);
stage.addChild(score);
這樣在舞臺上創建一個定時器並不斷增加,但是當我編譯時,我沒有得到任何錯誤,並且由於某種原因我的timmer不起作用,它只是顯示隨機數字,請幫助!如果有更好的方法,請啓發我。
那麼我怎麼能夠做一個計時器,以我在例子中所做的速度來計算呢? – BoneStarr
你不會,你可以做的是驗證自上次調用以來經過了多少時間並使用它。爲什麼你想要一些東西增加得如此之快呢?它不像用戶能夠看到它(文本將只根據frameRate刷新)。 – felipemaia
我想要一個類似於這樣的計時器:http://www.youtube.com/watch?v=Cx_r2ga7ipQ&feature=related – BoneStarr