简体   繁体   中英

Cocos2d v3 modal pause view implementation

I am trying to make my pause screen in my game. I am using the framework Cocos2d V3 RC4 in IOS and XCODE and SpriteBuilder. I read a lot of post and i think that i have two aproachs posible: 1º Push a total scene foward the main scene. (THIS WORK FINE TO ME) In the MAIN SCENE i call this to pause the game

CCScene *pausa = [CCBReader loadAsScene:@"Pausa"];
[[CCDirector sharedDirector] pushScene:pausa];

and then in the Pause class i call this to pop the pause scene and take back the Main scene:

[[CCDirector sharedDirector] popScene];

2º Take a CNode in front of the MAIN SCENE, making it with transparency, opaque, and disableing the main scene touch, animations, actions, etc… (THIS DOESN't WORK FOR ME AND I WHANT THIS !!!) I doit in this way:

In the main Scene:

CCScene *pausa = [CCBReader loadAsScene:@"Pausa"];
[self addChild:pausa];

AND I TRY with ALL THIS METHODS:

//    [self unscheduleAllSelectors];
//    [self stopAllActions];
//    [self setPaused:TRUE];
//    [self setUserInteractionEnabled:FALSE];

The node is added but Have not Touch exclusively… The Node that is behind I can touch it… I try olso with :

[[CCDirector sharedDirector] pushScene:pausa];

(in the main scene) with result obviosly bad, and i try with

[self setExclusiveTouch:TRUE]; 

in the pause didLoadFromCCB method but also I cant make it have a Exclusive touch. i Can STILLPRESS buttons and sprites from the back Node…

What I am doing Wrong, And how is the correct code/aproach tu use to handle a pause node like I want for method 2??

Resuming... I only want a Modal Window... (like in zk framework, in java, the Window (CNode in Cocos2d) come in front and the background keep disabled and in grey)

Thanks for read and hope someone can help

Here is my implementation from a game that I am doing

- (void) pauseGame
{
    CCLOG(@"Pause game");
    _contentNode.paused = YES;
    _contentNode.userInteractionEnabled = NO;

    _gamePausedNode = (GamePausedNode *)[self loadCCBWithNameAndPositionInCenter:@"PausedNode"];

    [self addChild:_gamePausedNode];
}

gamePausedGame is a CCNode , but it could be CCSprite as well. It is not actually a CCScene , nor is it loaded by one because a modal view like this is not really a scene.

You usually want to group the CCNode objects together in one CCNode like my _contentNode so you can pause them with one click.

Update : I have edited the code to the bare minimals

CCPhysicsNode *_physics;

_physics.paused = true; // It will pause your game but not actions.

_physics.paused = false; // It will resume your spinning and falling of sprites while button is pressable like during pause game.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM