I’m just trying to schedule an update method once in ccTouchesMoved, but when I add this
if (isRotating == YES)
{
gTimer = 20;
[self schedule:@selector(g:) interval:1];
}
in to ccTouchesMove it calls it every time the touch is moved. Is there a way to keep it in ccTouchesMoved and have it called just once?
isRotating is set to YES in ccTouchesMoved.
Code:
- (void)g:(ccTime)delta
{
gTimer--;
if (gTimer == 0 && isRotating == YES)
{
[self unschedule:@selector(g:)];
}
}
All I want to do is rotate a sprite for a fixed interval then remove it when the timer is 0, but I only want to remove it if the touch is currently rotating the sprite.
Here is where pausing/resuming the timer comes in. If the player starts rotating the sprite then lifts their finger, the timer should pause and when they touch/rotate the sprite again the timer should resume.
If my explaining isn’t clear please feel free to ask me to elaborate.
Timer methods:
In .h
ccTimer gTimer;
In .m
- (void)g:(ccTime)delta
{
gTimer--;
if (gTimer == 0 && isRotating == YES)
{
[self unschedule:@selector(g:)];
}
}
Also, I set the timer with
if (isRotating == YES)
{
gTimer = 20;
[self schedule:@selector(g:) interval:1];
}
Any help is greatly appreciated!
To pause the timer I just used
then to resume it I used
Also, for scheduling update in ccTouchesMoved I just checked to see if the finger and stopped moving without being lifted.