Torque 2D/StandardTutorials/Basics/PauseScreen

From TDN

Wouldn't it be cool to pause your game in a nice way?

Here's how I did it....

//define some game junk..
$gameName = "Placid";

//Define our Pause Window
new GuiWindowCtrl(pauseFullWindow) {
   canSaveDynamicFields = "0";
   Profile = "EditorWindowProfile";
   HorizSizing = "center";
   VertSizing = "center";
   position = "0 0";
   Extent = "640 480";
   MinExtent = "8 2";
   canSave = "1";
   Visible = "0";
   hovertime = "1000";
   text = "Alert";
   maxLength = "1024";
   resizeWidth = "0";
   resizeHeight = "0";
   canMove = "0";
   canClose = "0";
   canMinimize = "0";
   canMaximize = "0";
   minSize = "50 50";

   new GuiWindowCtrl(pauseWindow) {
      canSaveDynamicFields = "0";
      Profile = "EditorWindowProfile";
      HorizSizing = "center";
      VertSizing = "center";
      position = "220 190";
      Extent = "200 100";
      MinExtent = "8 2";
      canSave = "1";
      Visible = "0";
      hovertime = "1000";
      text = $gameName;
      maxLength = "1024";
      resizeWidth = "0";
      resizeHeight = "0";
      canMove = "0";
      canClose = "0";
      canMinimize = "0";
      canMaximize = "0";
      minSize = "50 50";

      new GuiButtonCtrl(pauseGameBtn) {
         canSaveDynamicFields = "0";
         Profile = "GuiButtonProfile";
         HorizSizing = "center";
         VertSizing = "center";
         position = "24 41";
         Extent = "140 30";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         Command = "pauseGame(t2dScene);";
         hovertime = "1000";
         text = "Game is Paused";
         groupNum = "-1";
         buttonType = "PushButton";
      };
   };
};


//****************************************************//
// getGamePaused
//
// returns the state of the pausing
//****************************************************//

function getGamePaused()
{
     return $gamePaused;
}
	   
//****************************************************//
// setGamePaused
//
// sets the state of the pausing
//****************************************************//

function setGamePaused(%val)
{
     $gamePaused = %val;
     echo("gamePaused set to" SPC %val);
     return getGamePaused(); 
}

//****************************************************//
// pauseGame
// 
// Given a SceneGraph it will pause scene.    
//****************************************************//
	   
function pauseGame(%obj)
{
     if(isObject(%obj))
     {
         if (getGamePaused())
         {
            echo("Resuming Game");
            canvas.popDialog(pauseFullWindow);
            setGamePaused(0);
            pauseWindow.setVisible(false);
            %obj.setScenePause(false);
            SetCanvasTitle($gameName);
         } else {
            echo("Pausing Game");
            setGamePaused(1);
            canvas.pushDialog(pauseFullWindow);
            pauseWindow.setVisible(true);
            %obj.setScenePause(true);
            SetCanvasTitle($gameName SPC "- Paused");
         }
      } else {
         echo("Non Object Reference Passed to pauseGame");
         return;         
      }
   }

moveMap.bindCmd(keyboard, "alt p"  , "" , "pauseGame(t2dScene);" );


Image:Pause-Screen-Example.png