Got your code. OMG I hate zombie conga :) but it was an great learning tutorial for me too. All your code looks fine. At least I couldn't see anything wrong with it. Game play is paused/un-paused correctly according to a couple NSLogs I dropped in. You are also pausing/un-pausing the right way according to RW's iOS Games by Tutorials page 481 (absolutely great book btw, I highly recommend it).
I believe the reason the pause function is not working properly is because the movements in the game are time based. For example:
_dt = currentTime - _lastUpdateTime;
shortly after the _dt line a call is made to move the sprite
[self moveSprite:_zombie velocity:_velocity];
which includes the line
CGPoint amountToMove = CGPointMultiplyScalar(velocity, _dt);
Un-pausing the game, will result character movements to be greatly exaggerated because a lot of time could have passed from when the game was initially paused.
The unexpected results you are having is caused by the game's logic rather than your programming skills. To remedy this specific app to function properly with pause, I would suggest changing the movement to incremental updates (e.g. x=x+1) in the update method instead of using time based calculated movement.
UPDATED: Included non time based movement code
//
// touch anywhere on the screen to move the object to that location
//
@implementation MyScene
{
SKSpriteNode *object1;
CGPoint destinationLocation;
}
-(id)initWithSize:(CGSize)size
{
if (self = [super initWithSize:size])
{
[self createObject];
destinationLocation = CGPointMake(300, 150);
}
return self;
}
-(void)createObject
{
object1 = [SKSpriteNode spriteNodeWithColor:[SKColor redColor] size:CGSizeMake(50, 50)];
object1.position = CGPointMake(300, 150);
object1.zRotation = 1;
[self addChild:object1];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
destinationLocation = [touch locationInNode:self.scene];
}
-(void)update:(CFTimeInterval)currentTime
{
float x = fabs(object1.position.x - destinationLocation.x);
float y = fabs(object1.position.y - destinationLocation.y);
float divider = 0;
if(x > y)
{
divider = x;
} else
{
divider = y;
}
float xMove = (x/divider)*2; // you can change the 2 to any value you want.
float yMove = (y/divider)*2; // just make sure both x & y are multiplied by the same value
if(object1.position.x > destinationLocation.x)
object1.position = CGPointMake(object1.position.x-xMove, object1.position.y);
if(object1.position.x < destinationLocation.x)
object1.position = CGPointMake(object1.position.x+xMove, object1.position.y);
if(object1.position.y > destinationLocation.y)
object1.position = CGPointMake(object1.position.x, object1.position.y-yMove);
if(object1.position.y < destinationLocation.y)
object1.position = CGPointMake(object1.position.x, object1.position.y+yMove);
}
@end