I have a sprite that I am rotating on a menu screen in my Cocos2d game like this:
CCAction* action = [CCRepeatForever actionWithAction:
[CCRotateBy actionWithDuration:1.0 angle:90.0f]];
[sprite runAction:action];
The problem occurs when I send the game to the background, and then resume the game. If the send to background / resume operation is quick there is a slight glitch. The longer the game stays in the background, the longer the sprite will "twitch" when the game resumes, before it will begin rotating normally again. I am on Cocos2d 2.0, Xcode 4.5, running on iOS 6.
Edit: Good point Gangcil! Here is what I had (it was, I believe, from the Cocos2d boilerplate:
// getting a call, pause the game
-(void) applicationWillResignActive:(UIApplication *)application
{
if( [_navController visibleViewController] == _director )
[_director pause];
}
// call got rejected
-(void) applicationDidBecomeActive:(UIApplication *)application
{
if( [_navController visibleViewController] == _director )
[_director resume];
}
I was able to get the problem to go away by changing these functions to:
// getting a call, pause the game
-(void) applicationWillResignActive:(UIApplication *)application
{
if( [_navController visibleViewController] == _director )
{
[_director stopAnimation];
[_director pause];
}
}
// call got rejected
-(void) applicationDidBecomeActive:(UIApplication *)application
{
if( [_navController visibleViewController] == _director )
{
[_director stopAnimation];
[_director resume];
[_director startAnimation];
}
}
I am not sure if this was the correct approach or not - there is a slight hesitation at first (understandably), but then the animation commences smoothly. The slight hesitation is better than the wild jittering that I saw before - but I don't know if this solution can be improved on.