by Jon (Updated on 2014-01-26)
Pausing is such a common feature that we decided to include it in the Stencyl engine itself.
We opted for a simple approach to pausing: pause everything and you tell us what should remain active. This gives you full control, and at the same time, it minimizes the amount of work on your part.
- Opting Out (Staying Active)
- Example: Simple Pause/Unpause
Pausing freezes all “When Updating” events for Actors and all physics, unless you opt them out of pausing. In contrast, All “When Updating” events for Scenes are unaffected by pausing.
All Drawing Events still happen.
To pause and unpause the game, use these blocks under Scene > Game Flow.
Opting Out an Actor (Staying Active)
Often, you’ll want some Actors to remain active while the game is paused.
To opt an Actor out, flip to its Physics > Advanced page. Select “No” for this option.
Example: Simple Pause/Unpause
Notice that pausing preserves the full state of the actors. The ball will continue at the exact same trajectory as before. Here's how this example works.
Event 1: Toggling the Pause State
This part toggles between paused and unpaused when you press the spacebar.
Event 2: Tinting the Screen when Paused
This part darkens the screen a little when while the game’s paused by drawing a semi-transparent black rectangle on top of everything.
- Pausing affects all actors by default.
- Pausing stops updates to actors but does not affect scene behaviors/events.
- Opt actors out to keep them active.
Challenge: Pause “Spell”
Who said that pausing had to be used just to pause the game? Let’s use pausing to create a Pause “Spell”, one that causes all enemies in a scene to freeze temporarily.
Create a game in which picking up a “timer” item will, for 30 seconds, cause all enemies to freeze up. Everything else will operate normally, including the player.