In cocos2d, the function call can be either direct call without any delay, or scheduled call with a delay.
In direct call, the syntax is as follows:
[self functionName]; // to call a function without delay
In scheduled function call, the syntax is:
[self schedule:@selector(functionName) interval:10]; // to call a function with delay = 10min.s.
Note: If the function is called with a selector with specified time interval(say 10min, as above), then it will get called in every repeated,specified time intervals(in the above case, it will trigger in every 10 min.s). So, if you need to stop the function getting called repeatedly, you can simply use the following line inside the called function at it's beginning.
[self unschedule:_cmd];
example:
function (normal):
-(void)myFunction{
.............................
.............................
.............................
}
scheduled call:
[self schedule:@selector(myFunction) interval:2];
to stop the function from getting called per each 2 mins,
rewrite the function as follows:
-(void)myFunction{
[self unschedule:_cmd]; // this will unschedule the scheduler
.............................
.............................
.............................
}
In direct call, the syntax is as follows:
[self functionName]; // to call a function without delay
In scheduled function call, the syntax is:
[self schedule:@selector(functionName) interval:10]; // to call a function with delay = 10min.s.
Note: If the function is called with a selector with specified time interval(say 10min, as above), then it will get called in every repeated,specified time intervals(in the above case, it will trigger in every 10 min.s). So, if you need to stop the function getting called repeatedly, you can simply use the following line inside the called function at it's beginning.
[self unschedule:_cmd];
example:
function (normal):
-(void)myFunction{
.............................
.............................
.............................
}
scheduled call:
[self schedule:@selector(myFunction) interval:2];
to stop the function from getting called per each 2 mins,
rewrite the function as follows:
-(void)myFunction{
[self unschedule:_cmd]; // this will unschedule the scheduler
.............................
.............................
.............................
}