What's the proper way to implement pause screen?

I wrote my Pause Menu class a few months ago when I still don’t have that much knowledge about cocos2d-x. I didn’t know unshceduleUpdate* andpauseSchedulerAndActions()* before, hence, the use of the pause flag. I’m too busy right now to rewrite the class so I just left it the way it was.

@Lance
Sorry, I meant Wasin had a pause flag in his and was wondering why. I completely understand why you did for yours as that is similar to how I had done mine as I was in the same boat not having much knowledge about cocos2d-x when I had done my framework so I have had mine setup the way I am used to with a pause flag and without event handling/scheduling (although I have made a few frameworks with event handling, especially in AS3 programming, I am still mostly used to non-event handling frameworks). I have only just now changed it and removed my pause flag with the new setup I did yesterday.

Thanks for pointing out Tim! It’s no need to use the flag now as we pause the schedule. I’ll update my code, and my comment above.

Just in case someone wants another simple approach… you can draw last frame (before pause) to a texture and use it as a background in a new pushed scene, something like this:

//scene to be visited/drawn by Render Texture
CCScene *currentScene = CCDirector::sharedDirector()->getRunningScene();

//new scene to be pushed to director
CCScene *newScene = CCScene::create();

//create Render Texture using design resolution size
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCRenderTexture *rt = CCRenderTexture::create( winSize.width, winSize.height );

//draw current scene to texture (this will visit/draw all children in currentScene)
rt->begin();
currentScene->visit();
rt->end();

//This is because I am using anti-alias (GL_LINEAR) in my graphics
rt->getSprite()->getTexture()->setAntiAliasTexParameters();
//If you need to use alias/pixelated (GL_NEAREST) in your graphics comment previous and uncomment following line
//rt->getSprite()->getTexture()->setAliasTexParameters();

//move rendered texture to layer position
rt->getSprite()->setAnchorPoint( ccp(0,1) );
//if you don't want to move the anchor point then do this
//rt->setPosition( rt->getSprite()->getTexture()->getContentSize() / 2 );

//add rendered texture to the new scene
scene->addChild( rt );
//--- add whatever you want to this new scene including a callback to pop this new scene from the director ---//

//push new scene (all actions will be paused automatically)
CCDirector::sharedDirector()->pushScene( newScene );

Warning: If you use this method onExit, onExitTransitionDidFinish, onEnter and onEnterTransitionDidFinish will be called (again) for the Layers on scene being paused after pushing/popping scenes. For example, onExit/onExitTransitionDidFinish will be called on paused scene’s nodes as soon as new scene is pushed to the director and onEnter/onEnterTransitionDidFinish will be called on resuming scene’s nodes after the stacked scene is popped from director. So if you have something being created/scheduled/deleted/unscheduled on these functions, be aware that they will be called again and this can lead to error or duplicates if not managed carefully.