Pause by score dialog

Pause by score dialog
0.0 0


Hi, everyone!
Have a trouble with pausing a game.
By game logic at an end of the game I need to stop all actions exclude music and sounds and draw the score dialog.


But dialog isn’t show but the game pause. If delete last string, it’s works normally.
How can I stop it and show dialog? Maybe I do it wrong?


hi ,

don’t use cc.director.pause() to pause your game , instead for example you can make an cc.Enum and add your game states in there , this way you can have a game state variable and change it to different states. like this :

gameState : cc.Enum({
        readyToPlay : 0,
        playing : 1,
        gameOver : 2

and in your script somewhere :

this.myGameSate = gameState.readyToPlay;

this way you can control your sounds and animations. i mean use this as a flag.

maybe something like this :

if(this.myGameState === gameState.pause){

i hope you got the idea.


It sounds like you may be trying to pause the game while running an animation of some sort to show your winDialog. I do something similar in my game where I want to pause the “game” portion of my code but keep the UI portion animating and responsive to input.

What I do is create a “gameRoot” node and a “uiRoot” node at the top level. Everything under the gameRoot will be paused when I hit the pause button, but my menus and other stuff still work and have nice animations (under the uiRoot node).

I’m not sure if it is necessary, but I found that it works best if I recursively pause all of the nodes under my “gameRoot” using functions like these:

    pauseNodeAndDescendants: function(node) {
        var that = this;
        node.children.forEach(child => {

    resumeNodeAndDescendants: function(node) {
        var that = this;
        node.children.forEach(child => {

So when I hit my pause button, I call pauseNodeAndDescendants on gameRoot and when I unpause I call resumeNodeAndDescendants on gameRoot.

I hope this helps.


it’s exactly what I need.
I was think that there is more elegant move in Cocos API. But it is not.
Does forEach cycle normal from point of view a processor load?
Is your code quick or it can implemented better?


Some useful information
Worked for my demand next functions:

this.enabled = false;

Pause a script execution. Because I have an object which move back and forth by scripts update() function.

this.node.pauseSystemEvents();    //resumeSystemEvents()

Node system events includes touch and mouse events. Because this object reacts on a screen touches.
I was create an additional Class named Stoppable and implement it by my scripts. It has pause() and resume().
In button’s handler:

this.node.children.forEach(child => {
    if (child.getComponent('Stoppable') !== null) child.getComponent('Stoppable').pause()


I’m not 100% sure but a “regular” for loop over the children array may be faster. On my relatively small scene-graphs (a few dozen nodes) I have tested my code in the simulator and on an 3rd generation iPad and an iPhone 5 and there is no perceivable delay between hitting the pause button and everything stopping.

I’m glad I could help.