私はフラッシュ ゲームを作成しています。これは、プレーヤーが現在のレベルでプレイしている時間を示すタイマーです。問題は、ここでゲームが開始されたときにタイマーがなく、1 秒後にのみ表示され、その後 00:01 秒が表示されることです。ゲームの開始時にタイマーがすぐに表示され、00:00 が表示されるようにする必要があります。
これが私の主な機能です。
public function MemoryGame()
{
addChild(CardContainer);
tryAgain.addEventListener(MouseEvent.CLICK, darKarta);
timer = new Timer(1000); //create a new timer that ticks every second.
timer.addEventListener(TimerEvent.TIMER, tick, false, 0, true); //listen for the timer tick
timer.addEventListener(TimerEvent.TIMER, resetTimer);
txtTime = new TextField();
addChild(txtTime);
tmpTime = timer.currentCount;
timer.start();
_cards = new Array();
_totalMatches = 18;
_currentMatches = 0;
createCards();
}
これが私のタイマーです:
private function tick(e:Event):void {
txtTime.text = showTimePassed(timer.currentCount - tmpTime);
}
function showTimePassed(startTime:int):String {
var leadingZeroMS:String = ""; //how many leading 0's to put in front of the miliseconds
var leadingZeroS:String = ""; //how many leading 0's to put in front of the seconds
var leadingZeroM:String = "";
var time = getTimer() - startTime; //this gets the amount of miliseconds elapsed
var miliseconds = (time % 1000); // modulus (%) gives you the remainder after dividing,
if (miliseconds < 10) { //if less than two digits, add a leading 0
leadingZeroMS = "0";
}
var seconds = Math.floor((time / 1000) % 60); //this gets the amount of seconds
if (seconds < 10) { //if seconds are less than two digits, add the leading zero
leadingZeroS = "0";
}
var minutes = Math.floor((time / (60 * 1000) ) );
if (minutes < 10) { //if seconds are less than two digits, add the leading zero
leadingZeroM = "0";
}
//60 seconds times 1000 miliseocnds gets the minutes
return leadingZeroM + minutes + ":" + leadingZeroS + seconds + "" + leadingZeroMS ;
}
回答ありがとうございます。