2011-03-30 11 views

回答

19

getTimer()將返回從閃存啓動時起精確到多少毫秒的整數。

import flash.utils.getTimer; 

var myInt:int = getTimer() * 0.001; 

然而,myInt現在會運行很多秒的程序。

編輯:哦告訴它已經運行了多長時間,只保留最初的myInt,並根據當前定時器檢查它。

所以當遊戲第一次啓動時。

var startTime:int = getTimer(); 

然後每幀或每當你需要檢查它。

var currentTime:int = getTimer(); 


var timeRunning:int = (currentTime - startTime) * 0.001; // this is how many seconds the game has been running. 
+0

http://help.adobe.com/en_US/as2/reference/flashlite/WS5b3ccc516d4fbf351e63e3d118cd9b5f6e-7a54.html 有一點含糊,我在IDE的getTimer看到返回int,而閃存的文件說getTimer返回Number。知道一個是正確的將是有用的。歡呼 – GameDeveloper 2013-05-10 05:21:05

+0

頭文件(庫)中的函數聲明是「公共函數getTimer():int」,所以它返回一個int。順便說一下,這些是actionScript 2引用而不是actionScript 3引用。 http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/package.html#getTimer() – Feltope 2013-05-14 07:34:22

+0

你救了我headhackes :) – GameDeveloper 2013-05-16 07:27:55

1
var a:int = 0; 

var onTimer:Function = function (e:TimerEvent):void { 
    a += 2; 
} 

var timer:Timer = new Timer(1000); 
timer.addEventListener(TimerEvent.TIMER, onTimer); 
timer.start(); 
0
var countdown:Timer = new Timer(1000); 
countdown.addEventListener(TimerEvent.TIMER, timerHandler); 
countdown.start(); 

function timerHandler(e:TimerEvent):void 
{   
    var minute = Math.floor(countdown.currentCount/60); 
    if(minute < 10) 
     minute = '0'+minute; 

    var second = countdown.currentCount % 60; 
    if(second < 10) 
     second = '0'+second; 


    var timeElapsed = minute +':'+second; 
    trace(timeElapsed); 
}