Aaleks Aaleks - 3 months ago 29
Objective-C Question

pause the currentTime of -(void)update:(CFTimeInterval)currentTime

I would like to know if it is possible to pause the currentTime in -(void)update:(CFTimeInterval)currentTime

i succeed in pausing my scene by using this:

self.view.paused=YES;
self.paused=YES;
self.scene.view.paused = YES;


It works but in -(void)update i have this method:

[_landscape update:currentTime];


And the problem is that the currentTime don't stop to increase even if the scene is paused.
After i resume the scene, my _landscape velocity change.

Answer

i don't know if you have figured out the answer to this question yet, but here is the solution that i think will resolve your issue. what you need to do is to set the current time of your game to zero, so when un pausing the game there will be no lapse of time. in another word the whole animations will stop and will resume at the very point that you have pause the game. i use this method in my update for stoping the current time.

if (_lastUpdateTime) {
        _dt = currentTime - _lastUpdateTime;
    } else {
        _dt = 0;
    }
    _lastUpdateTime = currentTime;

    if (_pauseButtonPressed) {
        _lastUpdateTime = 0;
        return;
    }

the first part sets the current time and delta time and the second part will set the current time to zero if the game is paused. hope this will help you out.:)

Comments