Laya 實操五:定時器

定時器

export default class Test extends Laya.Script {
    constructor() { super(); }

    onStart(){
        //n幀後運行一次
        //Laya.timer.frameOnce(300,this,function(){console.log("ok");});
        //每隔n幀,循環運行
        //Laya.timer.frameLoop(300,this,function(){console.log("ok");});
        //n毫秒後運行一次
        //Laya.timer.once(1000,this,function(){console.log("ok");});
        //每隔n毫秒,循環運行
        //Laya.timer.loop(1000,this,function(){console.log("ok");});

        //let func = function(){console.log("ok");}
        //Laya.timer.loop(2000,this,func);
        //取消一個定時器
        //Laya.timer.once(10000,this,()=>{Laya.timer.clear(this,func)});
        //取消所有定時器
        //Laya.timer.once(10000,this,()=>{Laya.timer.clearAll(this)});

        //下一幀執行
        //Laya.timer.callLater(this,function(){console.log("ok");});

        //let func = function(){console.log("ok");}
        //Laya.timer.loop(1000,this,func);
        //立即執行一次,並取消此定時器
        //Laya.timer.once(2000,this,function(){Laya.timer.runTimer(this,func)});

        //含參
        //let func = function(p1,p2,p3){console.log(p1,p2,p3);}
        //Laya.timer.once(3000,this,func,[24,true,"aaa"]);

        //Laya.timer.scale  = 1;//時間縮放
    }

    onUpdate(){
        //console.log(Laya.timer.currFrame);//當前幀數
        //console.log(Laya.timer.currTimer);//當前幀開始的時間戳
        //console.log(Laya.timer.delta);//距離上一幀時間
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章