user819640
user819640

Reputation: 250

Does the deltaTime from a scheduled method take into consideration time where CCDirector is paused?

I have an update method that is called every frame. Each update, it adds its deltaTime on to a variable.

If I pause CCDirector and after a while I resume it, will the deltaTime in that scheduled method be massive?

I ask because I am tracking down a bug where on some devices the player can press the home button on an iOS device and then after some time resume the app and the variable that holds their totalGameTime has still been added on as if the game hasn't been paused.

I was under the impression this shouldn't happen when I use cocos2d schedulers.

The code for anyone who feels they need it

//[self schedule:@selector(myUpdate:)];

float totalGameTime

-(void) myUpdate:(ccTime) dt {

    totalGameTime += (float) dt;
}

Upvotes: 1

Views: 270

Answers (2)

James Webster
James Webster

Reputation: 32066

I've noticed this happen too but only in release. I fixed it by adding:

[[CCDirector sharedDirector] setNextDeltaTimeZero:YES];

to my -(void) applicationDidBecomeActive:(UIApplication *)application

This may perhaps be a bug in version 2.0 as I don't remember this happening prior to this version.

Upvotes: 2

CodeSmile
CodeSmile

Reputation: 64477

No. To my knowledge cocos2d resets the delta time if you pause it or if some large amount of time has passed due to an OS interruption (incoming call or something).

You can also easily test that by logging delta time. If need be log it only if it's greater than 0.1f or so.

Upvotes: 1

Related Questions