Game Development Community

How To Pause A Game Effectively. (Already tried setting $timeScale).

by Jack-S- · in iTorque 2D · 11/26/2011 (8:58 am) · 4 replies

Hi, I was wondering if anybody knows how to pause iTorque properly?
Basically in my game I would like to have a pause menu however I have tried a few things already such as $timeScale and setPaused() etc however with no avail.
$timeScale pauses the game but also pauses all interaction with any buttons I have in the hud aswell.

setPaused hasnt proven very usefull either in that it only stops an object however if that object has a behavior that is moving it say random velocity behavior or follow the player then the object unfortunately doesnt pause...

ill admit that im now clueless on how to effectively pause my game while allowing the player to still interact with it....
Has anyone got any work arounds??
Thanks in advance.

#1
11/26/2011 (7:54 pm)
Hello,

I do all my programming in the C++ side of iTorque, so I use sceneGraph->setScenePause(true); for paused and sceneGraph->setScenePause(false) for unpaused.

BUT I did a bit of digging and I BELIEVE that you can simply call SceneWindow2D.getSceneGraph().setScenePause(true) for paused and
SceneWindow2D.getSceneGraph().setScenePause(false) for unPaused, In TorqueScript.

Hope this works, Good luck.
#2
11/27/2011 (6:51 am)
@ Daniel sounds AWESOME! I will give this a shot today to see if this works. I am using two scenes (one for hud and one for actual level) so being able to pause just once scene will be great. Thanks!
#3
11/27/2011 (2:12 pm)
Hey that will work, however keep in mind that, last I checked (in torque 2D 1.7.5) all 'schedule' calls are independent of the scene and do not get paused by "setScenePause"
#4
01/31/2012 (6:01 pm)
As far as I can tell when pause is active, all the timers currently active will finish executing, including the code that the timer activates. This is an annoying little backdoor the engine has. My suggestion is to use a check such as the one below to avoid executing code during pause.

if (!SceneWindow2D.getSceneGraph().getScenePause())
then...

In my case I still want the timer to be set, but I don't want new instances f objects to be created and drawn, so I keep my schedule call outside of this condition.

It would be nice if there was an onResume event callback that would activate when pause is lifted so that I did not need the above to avoid losing my schedule call (it is recursive in that the function schedules itself to be called again). Does anyone know of something like an onResume event?