cocos2dx中有三種定時器:
schedule,scheduleupdate,scheduleonce。
1. schedule 的用法:
先定義乙個函式 void updatetime(float ft);
//開啟自定義定時器
schedule(schedule_selector(helloworld::updatetime), 1.0); 每間隔1s呼叫一次updatetime函式執行
unchedule(schedule_selector(helloworld::updatetime)); //終止定時器
2. scheduleonce
功能:在幾秒之後執行,並且只執行一次。
//開啟定時器
scheduleonce(schedule_selector(helloworld::updatetime), 1.0); 間隔1s呼叫一次updatetime函式執行 (指呼叫一次)
3. schedule
引擎自帶的函式的 void update(float ft); //重寫該函式就行
//開啟定時器
this->schedule();
//終止定時器
this->unschedule();
cocos2d x 關於定時器
定時器的作用就是每隔一段時間,就執行一段自定義的動作,比如飛機向前方移動,子彈的移動等等。該函式定義在ccnode標頭檔案中,基本上cocos2dx中所有的東西都能夠使用定時器。第一種 scheduleupdate 預設定時器 該定時器開啟函式與update 函式配套使用,update方法是每一幀執...
cocos2dx定時器事件
update定時器 schedule定時器 其他事件 除了定時器會不斷地提供觸發事件外,cocos2d x還為我們提供了一些其他與流程控制相關的事件 方法名稱 描述 onenter 當此節點所在場景即將呈現時,會呼叫此方法 onentertransitiondidfinish 當此節點所在場景的入場...
Cocos2d x之定時器
每乙個遊戲程式都有乙個迴圈在不斷執行,它是由導演物件來管理與維護。如果需要場景中的精靈運動起來,可以在遊戲迴圈中使用定時器對精靈等物件進行操作。因為node類封裝了scheduler類,所以也可以直接使用node中呼叫函式。定時器的兩種實現方式 scheduleupdate 是定時器更新函式,如果定...