Game Development Community

GamePadState and Pausing

by John Bura · in Torque X 2D · 07/05/2010 (8:20 pm) · 7 replies

So I have traditionally paused my game with a GamePadState similar to this tutorial.http://msdn.microsoft.com/en-us/library/bb195026.aspx

But I can't seem to find the torque equivalent.

Here is what I am using to pause
map.BindCommand(gamepadId, (int)XGamePadDevice.GamePadObjects.Start, pause, null);

and here is what my pause method looks like
void pause()
        {
            Game.Instance.Engine.GameTimeScale = 0f;  
        }

But I cannot figure out how to get out of the pause. I have tried setting up a counter to check how many times I push start. I have also tried booleans. But I just can't get it to work. What is an easy way to pause the game.



#1
07/05/2010 (10:13 pm)
In your pause class(not in the method) put a private bool _isPaused; and change your pause method to this:
void Pause()
{
    if (!_isPaused) Game.Instance.Engine.GameTimeScale = 0f;
    else Game.Instance.Engine.GameTimeScale = 1f;
    _isPaused = !_isPaused;
}
#2
07/06/2010 (9:50 am)
My pause method involves creating an interface called IPauseable, and applying it to all objects which I think should be pause able. Then modifying a single line in the process tick to check if the game is paused, and if it is, not to update the paused objects... This allows you to continue to use the process tick during pause situations, to drive your pause menu's if needs be... I rely on it heavily, and so far it works. If you want i can post an example.
#3
07/06/2010 (10:39 am)
Awesome Guys I figured it out. :)

Thanks for all of the help as usual.
#4
07/06/2010 (10:48 am)
hey Will, can you still post some examples? I've been trying to figure out something like what you're doing, since right now the entire game engine pauses. Thanks, Ray
#5
07/06/2010 (11:22 am)
Ok, first, add this interface to the "ProcessList.cs" just an interface any object can extend, i put it at line 58.

public interface IPauseable
    {

    }

Also, add a public property so that your process list is pauseable, i find it more useful to just pause the process list.
//line230
        public bool IsPaused
        {
            get { return _isPaused; }
            set { _isPaused = value; }
        }
//line999
bool _isPaused = false;

Of course you could add a public property, like "IsPauseable" but right now that would be redundant in my engine, but you could do that. Once that's done, add the interface to objects you wish to stop recieving update's when your game is paused, a good example for me was the "T2DPhysicsComponent" Heres line 60 of my T2DPhysicsComponent
public class T2DPhysicsComponent : TorqueComponent, ITickObject, IDisposable, IPauseable
One this is done, you should be free to add the modifying code to the process list, and check your results. heres the code
//line 725
  while (tickIdx != -1)
                    {
                        if (_isPaused && _tickNodes[tickIdx]._callback is IPauseable) { }
                        else
                        _tickNodes[tickIdx]._callback.ProcessTick(move, tickSec);

That pretty much wraps it up, obviously theres alot of different way's to do what i just did, thats just the method i thought worked best.
#6
07/06/2010 (11:48 am)
For my pausing I've just got a simple global state machine.

I've got an enum for every state in my game and all of my process ticks and button presses check the game state to see whether it should process, or in the case of buttons, what action it should take (if any).

I like your idea though will, I might implement that in my next project. I like the idea of skipping the tick entirely instead of going in, checking a state then skipping the code.
#7
07/06/2010 (10:10 pm)
My next step I think would be to do a completely different loop if the game is paused, vs if the game is not paused... that would certainly minimize the checking of whether or not the game is paused...