CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2011
    Posts
    1

    Pausing Snake game

    I was wondering what the best way to pause my game would be? I've tried everything i can thing of and im not sure where to go next. Java source file is attatched.
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2008
    Posts
    966

    Re: Pausing Snake game

    Sorry, most of us will not open attachments. I hope you can understand why. Please post the code inside of code tags so that we can see what you are trying to do and then we can help you out.

  3. #3
    Join Date
    Jan 2011
    Location
    Tacoma, Washington
    Posts
    31

    Re: Pausing Snake game

    as a general rule I usually have a boolean like is_paused. Then an Action that sets the boolean according to the desired state (generally a toggle for the is_paused flag). Then, anything that would care about the state of the pause flag checks it's condition (such as a movement button clicked to move a sprite).

    Code:
    //a call to do something maybe from actionPerformed() from a listener.
    if (!is_paused)
    {
      //do your rad stuff here because the game isn't paused
    }
    else
    {
      //of course the default for paused is do nothing but you could have other things happen during
      //pause.  I like obscuring the screen so no pause cheating.
    }
    This allows the rest of the program to continue as normal and only the things that shouldn't work during a paused state are blocked.

    Hope that helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured