GameCorder.net

このエントリーをはてなブックマークに追加

callback function with delay time

there has a time want to wait seconds time and call callback function.
In this case.cocos2dx has a class name DelayTime.
Let's see example.

In my case,I want to move sprite and wait 3seconds and call specific function


// first move
MoveTo* upToCenter = MoveTo::create(2, Vec2(DISPLAY_WIDTH / 2,DISPLAY_HEIGHT / 2));
// wait 3 seconds
DelayTime* delayTime = DelayTime::create(3);
// callback function 
auto callback = CallFunc::create(CC_CALLBACK_0(BaseStage::popBackTitle,this));
// do sequence
Sequence* sequence = Sequence::create(upToCenter,delayTime,callback,nullptr);
// act in this case Label ui
stageLabel->runAction(sequence);
	

In Sequence::create 3 step action.
first move wait call function.
Of course we can input 4 arg.

I confirm version 3.15.1.