Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Can someone please explain the basics of pausing a game — Gideros Forum

Can someone please explain the basics of pausing a game

Tom2012Tom2012 Guru
edited November 2012 in General questions
Trying to get my head around how to pause movement and everything else in a game.

Where's the best place to start with this?

Thanks

Tom

Comments

  • john26john26 Maintainer
    If you have a single update function, just tell it to do nothing:
    function update()
     
      if paused then
        return
      end
     
      -- update all sprites here
     
    end
    If you have an OO system with each object updating itself, you'll have to do more work, but it's similar.
  • Thanks John.

    And with Box2D, I'm guessing you just stop it doing the step each frame?
  • john26john26 Maintainer
    edited November 2012
    Yes, that's right. The Box2D update call (b2.World.step) would also be in "update", so in pause mode, update doesn't call that and all physics objects are suspended in mid air. Of course touch listeners will still operate allowing the player to resume the game.

    In a real game, you probably don't just want to pause the game like that, you probably want to have some sort of menu perhaps with its own animation. In that case, you could remove the "update" event listener and start another update listener.
  • @Tom2012 :) I am in same trouble because i am lazy pumpkin and I forgot to put the code in update subroutines in all my actor objects and when i stop box2d, ships stop moving and shooting but some non box2d weapons like flamethrower and Tesla coils still do their dirty job. Was so in a hurry to see all actors alive and forgot the base function of pausing the game.
  • If you use sceneManager you can just transition to a "paused" scene.
    Although normally as mentioned above it requires the use of a state based system - basically you have a variable with one value to represent the normal game and a second to represent the paused state, then based on the value of that variable you can choose to execute your game code or not.
    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
  • @techdojo Exactly, but how much i hate to put one more boolean check in update cycles :)
  • @plamen one more reason to not have too many enterframe listeners :) however if you keep a list of all objects, couldn't you just write a single function that removes the enterframe listeners for each object (onEnterPause) and then add's them again after (onExitPause)
    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
  • @techdojo i have no problem to swap the enter frame listeners with simple update function. My objects are many but classes are not so many , its not really of a problem. I am thinking of updating logic with half of graphics update rate.
Sign In or Register to comment.