Like other game engines, we have two different ways to complete draw and update.
1: Draw: Each CCNode has a draw method, and each frame is called. We only do what is depicted in this method.
2: Update: by default, CCNode does not have update. If you want to Update the status, you can register a callback function in the following four ways:
ScheduleUpdate:
ScheduleUpdateWithPriority:
ScheduleSelector :( SEL) selector
ScheduleSelector: (SEL) selector interval :( float) interval
The registration method is called only when the current scenario is active and there is no Pause. We recommend that you use scheduleUpdate or scheduleUpdateWithPriority. Because it runs faster and consumes less memory. For example:
-(Id) init
{
//-10 indicates the priority. The smaller the value, the higher the priority.
[Self scheduleUpdateWithPriority:-10];
}
-(Void) update :( ccTime) deltaTime
{
// Update your node here
// DON't draw it, JUST update it.
// Example:
Rotation _ = value * deltaTime;
}
After scheduleUpdate or scheduleUpdateWithPriority is called, the system will find the update method we have defined, which is equivalent to schedule's update method. The update method for removing registration can be:
[Node unscheduleUpdate];
We can also use scheduleSelector, which is an old method with no priority. If no interval exists or if interval = 0, each frame is called.
-(Id) init
{
// The "step:" selector will be called every 0.5 seconds
[Self schedule: @ selector (step :) interval: 0.5f]
}
-(Void) step :( ccTime) deltaTime
{
// Update your stuff here
}
Cancel this method:
[Node unscheduleSelector: @ selector (step :)];