scheduleUpdateForTarget usable?

Schedule documentation

In documentation of Scheduler, the schedule method has the following description:

The scheduled method will be called every ‘interval’ seconds.
If paused is YES, then it won’t be called until it is resumed.
If ‘interval’ is 0, it will be called every frame, but if so, it recommended to use ‘scheduleUpdateForTarget:’ instead.
If the callback function is already scheduled, then only the interval parameter will be updated without re-scheduling it again.
repeat let the action be repeated repeat + 1 times, use cc.macro.REPEAT_FOREVER to let the action run continuously
delay is the amount of time the action will wait before it’ll start

however if I log cc.director().getScheduler().scheduleUpdateForTarget it returns undefined

it this function even exists?

You don’t need to get scheduler. You can schedule everything you want in a component. Everything will be handled by schedulerin background. I’ve checked the engine source and found “scheduleUpdateForTarget” is deprecated. I think documentation is not up to date.

Example how to use schedule in onLoad function of your component:

onLoad(){,
	// This is for calling each frame
	this.schedule(this.My_Scheduled_Function_On_Each_Frame,0);
	
	//This is for calling eevry 0.5 seconds
	this.schedule(this.My_Scheduled_Function_On_Half_Second,0.5);
},

My_Scheduled_Function_On_Each_Frame(){
	//...
},

My_Scheduled_Function_On_Half_Second(){
	//...
}

Hope it helps :wink:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.