Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to Pause and Unpause Game?

Explorer ,
Jul 24, 2015 Jul 24, 2015

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.

TOPICS
ActionScript
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jul 25, 2015 Jul 25, 2015

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  }

Translate
LEGEND ,
Jul 24, 2015 Jul 24, 2015

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 24, 2015 Jul 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 24, 2015 Jul 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 25, 2015 Jul 25, 2015

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 25, 2015 Jul 25, 2015
LATEST

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  }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines