Skip to main content
Inspiring
July 24, 2015
Answered

How to Pause and Unpause Game?

  • July 24, 2015
  • 1 reply
  • 1259 views

So I made a function that allows the player to hit the "p" key which will change the framerate of the game:

if (keys[80])

    {

        if(game_paused =="false"){

        stage.frameRate = 0;

        game_paused = "true";

        }

        if(game_paused =="true"){

        stage.frameRate = 30;

        game_paused = "false";

        }

    }

The problem is, when the key is pressed, the game seems to go at double the framerate, like 60 or maybe even higher than that. I have no clue why, I don't see how making the framerate EQUAL 30 would make it go HIGHER than that... any ideas? Thanks.

This topic has been closed for replies.
Correct answer Ned Murphy

It's a two-player side-scroller fighting game. It's kind of difficult to just say how the game code works because there's so much to it, but basically, pressing certain keys on the keyboard will allow the characters to move around, attack, etc. The battle portion of the game takes place on a single frame. I'll try using 0.01.


If it is all code-based, then chances are you need to deal with disabling anything that processes when you click the pause button.  It can get fairly complex depending on how much you have going on at any given time.  You might be able to simplify some of it if you build in conditional code where needed that essentially checks if a paused variable is set or not....

if(!game_paused) {  code that processes when the game is running  }

1 reply

Ned Murphy
Legend
July 24, 2015

Without knowing more about your design I would say instead of changing the frameRate to 0, use stop();

Inspiring
July 24, 2015

The stage of the game takes place on one frame, there's many variables as well. Stop(); wouldn't do anything other than stop the already stopped frame.

Ned Murphy
Legend
July 24, 2015

Well, that's a start.  Can you explain more about how your game code works?  It might lead to getting some help with a solution.

Meanwhile, the valid range for the frame rate is from 0.01 to 1000 frames per second - meaning you cannot stop it, but specifying a 0 for it could lead to issues like you see.  You should check out the help documentation to learn more about how the frameRate property works.