16,126

Views

Beginner

Level

6

Comments

Pausing

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.


Contents

  • Pausing
  • Opting Out (Staying Active)
  • Example: Simple Pause/Unpause


Pausing

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.

Note: What about "do every N seconds" events? These also remain active. If you wish to pause them, wrap their contents in an if-statement checking whether the game is not paused.


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.



Summary

  • 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.

Disclaimer: All articles are geared towards Stencyl 3.0 and above. Use comments to provide feedback and point out issues with the article (typo, wrong info, etc.). If you're seeking help for your game, please ask a question on the forums. Thanks!

6 Comments

Jon
Yuri - I've added a small blurb on that case. The answer is that pausing does not affect those events. You'll need to wrap them in an if-statement.

Roja - That no longer applies to Stencyl 3. In 2.0, Flixel's default binding for p is its internal pause menu.

0 2 months, 3 weeks ago
YuriG
And how to pause a "do every N seconds event" it drops actors to scene. but pause do nothing to it. How i fix this??
0 4 months, 5 days ago
patrickjavier
how to unpause:(

1 9 months, 4 weeks ago
rojasstencylman
for the example to pause u press space, but if u press "p", it will bring up the standard pause menu. Is there any way to get rid of the pause menu?
0 1 year, 4 months ago
hujiandong
sorry~!
I take a scene behavior to an actor~

0 1 year, 7 months ago
hujiandong
using the event1 code?can pause game,why can't unpause?
2 1 year, 7 months ago

Sign In to Comment