As of late 2021, we are in the process of updating Stencylpedia and fixing up outdated & broken content. Thanks for your patience!

64,591

Views

Beginner

Level

11

Comments

Pausing

by captaincomic (Updated on 2015-11-20)


Contents

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

Overview

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 by default.
  • You tell us what should remain active.

This approach gives you full control, and at the same time, it minimizes the amount of work on your part.

How To: Pause

To pause and unpause the game, use these blocks under Scene > Game Flow.

Pause Blocks

Details

What exactly is paused and what remains unpaused?

  • All When Updating events for Actors will stop happening (unless opted out)
  • All Do Every and Do After events for Actors events will stop happening
  • All physics for Actors will be paused (unless opted out)
  • All When Updating events for Scenes will continue to happen
  • All Drawing events still happen (but paused actors will not animate)

Gotcha: Pause Buttons

When pausing using a pause button actor, do not forget to opt the pause button out of pausing. Otherwise, the button itself will be frozen and unable to receive click events.

Opting Out an Actor (Staying Active)

Actors that opt out of pausing will remain active while the game is paused. To opt an Actor out, flip to its Physics > Advanced page. Select “No” for the Can be Paused? option.

Physics Page

Example: Simple Pause/Unpause

Event 1: Toggling the Pause State

This part toggles between paused and unpaused when you press the spacebar.

Event 1

Put this inside a scene behavior, or else it will stop working once the game is paused, leaving you stuck in the paused state.

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.

Event 2

As mentioned above, drawing events happen regardless of paused state.

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.

Print Article Edit Article How to Edit an Article
Disclaimer: 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!

11 Comments

Jon
I've reworked the article to make it clearer.

The "standard pause menu" that some refer to was part of Stencyl 1.x/2.x and no longer exists in Stencyl 3.

1 8 years, 11 months ago
derekfc
We could not get it to "unpause", as we were using an Event attached to a Pause Actor Button for pause / unpause code blocks.

FIX was to do the following:
1) Set Button as part of the Button Group, not general Actor Group
2) Button Actor / Physics / Advanced / "Can be Paused?" set to "No"
The second seemed the most important, as if the button can be paused, when in a pause state, that Pause Button Actor will be disabled as well.
When it cannot be paused, it enables the "unpause" functionality.

This is described above, but it is easy to forget the Pause Button (if used) is an actor of whatever type you set, and is also impacted by the Pause event, unless turned off as described above.

0 9 years, 1 month ago
IsaacsGames
Great tutorial! But 2 things, the example game is not working anymore, and I've seen lots of Stencyl games with the same pause menu that has up and down volume and mute volume. I'm talking about the one like on this game: http://www.stencyl.com/game/play/10 632
0 9 years, 1 month ago
vvitek
I'm using Stencyl 3.1.
I have a scene behaviour (which should not be paused, right?) and some commands within WhenGameIsPaused wrapper.
Still the commands are not executed until I UNpause the game.
Am I doing smthg wrong or...?
screenshot http://clip2net.com/s/il3Nsy

1 10 years, 3 months ago
Almakos
What this article misses is a clear explanation that you can unpause game only if you are checking whether game is paused in "When Updating" or "When Drawing" events...
For me it was not clear why i cannot unpause game on key press event by using "unpause game" block.

1 10 years, 4 months ago
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 10 years, 8 months 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 10 years, 10 months ago
patrickjavier
how to unpause:(

1 11 years, 3 months 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 11 years, 9 months ago
hujiandong
sorry~!
I take a scene behavior to an actor~

0 12 years, 1 month ago

Sign In to Comment