Pausing

by captaincomic (Updated on 2015-11-20)


Contents

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:

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?

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

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.