PauseThisScreen
Introduction
PauseThisScreen can be used to implement pausing. In many cases, this function will effectively provide pause implementation for games.
Example Usage - Pausing With the Keyboard
The following code shows how to pause and unpause the screen using a gamepad's Start button.
When the game is paused, the Sprite automatically stops rotating and resumes when the game is unpaused.
Applying Movement After Pause
When a Screen is paused, the underlying engine logic does not stop. Rather, the velocity of all objects is stopped and stored in instructions. When the screen is unpaused, all velocity values are re-applied. This means that if a velocity is changed after a screen is paused, the object which has been given velocity (or acceleration) will continue to operate while everything else remains paused. Furthermore, whenever a Screen is paused, its CustomActivity continues to be called every frame even while paused. Therefore, you can perform additional logic after a pause.
Example - Applying Movement After Pause
The following code assumes an Entity named Ball. Clicking the cursor creates a new Ball which falls. Pressing the Space toggles pause. Notice that pausing the game will pause all existing entities, but new entities created after a pause will fall normally.
Example - Playing Gum Animations After Pausing
Gum animations internally create Tweeners on the TweenerManager. When the Screen is paused, all Tweeners are paused. If your game includes a Gum object which animates when the game is paused (such as a menu sliding on the screen), you can play the animation after the PauseThisScreen call and the animation will still play normally.
The following code animates a button on-screen after the game is paused.
If you have animations which should persist through pausing, see the ObjectsIgnoringPausing section below.
InstructionManager.ObjectsIgnoringPausing
Example - Playing Gum Animations when Paused
Calling PauseThisScreen also pauses the TweenerManager, which inturn pauses all Gum animations. Animations can be excluded from this pausing by adding the animation to the InstructionManager.ObjectsIgnoringPausing. Note that the animation must be added, not the Gum or Forms object.
The following code begins a Button's looping animation in CustomInitialize. Its animation is added to InstructionManager.ObjectsIgnoringPausing which results in the button continuing to animate even if the game is paused.
Notice that when the game is paused the player's movement stops but the Button continues to animate.
Last updated
Was this helpful?