phantomsri
phantomsri

Reputation: 11

how to resume to correct layer after app terminates (cocos2d)

Hi i need help with this code. In my game i have main layer which has menu button for options and game level. And I have a game layer to play the game.

When I terminated the app by clicking the home button and i relaunch the game again,it starts in the correct spot i left.

My questions is when i terminate in the game layer i want to launch a resume/pause layer when it resumes, and when i terminate the game in the main layer i dont want to launch resume/pause layer. how can i do that?

currently here is my code.

- (void)applicationWillResignActive:(UIApplication *)application {
[[CCDirector sharedDirector] pushScene:[PauseScene scene]];
}

I hope someone can help me coz im still learning on ios programming

Upvotes: 0

Views: 473

Answers (1)

Alexander
Alexander

Reputation: 8147

Try with this:

- (void)applicationDidBecomeActive:(UIApplication *)application {
    if (nil != [[[CCDirector sharedDirector] runningScene]) {
        // make sure we have a scene to release, 
        // since this method is invoked on start up, too
        [[CCDirector sharedDirector] popScene];
        [[CCDirector sharedDirector] resume];
    }
}

- (void)applicationWillResignActive:(UIApplication *)application {
    [[CCDirector sharedDirector] pushScene:[PauseScene scene]];
    // pause CCDirector, so we can keep any scheduled events for later
    [[CCDirector sharedDirector] pause];
}

Upvotes: 1

Related Questions