Skip to main content

Pause System

The Pause System provides a flexible way to pause and resume entities in your game. This system allows you to selectively pause certain entities while allowing others to continue updating, giving you fine-grained control over your game's pause behavior.

Overview

The Pause System consists of two main components:

  • PauseComponent - A component that already is attached to Actors
  • PauseSystem - A system that manages pause state across all entities in a scene

Quick Start

ts
// Create an actor that can be paused
const player = new ex.Actor({ x: 100, y: 100, canPause: true });
scene.add(player);
 
// Pause the scene
scene.pauseScene();
 
// Resume the scene
scene.resumeScene();
ts
// Create an actor that can be paused
const player = new ex.Actor({ x: 100, y: 100, canPause: true });
scene.add(player);
 
// Pause the scene
scene.pauseScene();
 
// Resume the scene
scene.resumeScene();

PauseComponent

The PauseComponent tracks whether an entity is currently paused and whether it can be paused.

Properties

PropertyTypeDefaultDescription
pausedbooleanfalseWhether the entity is currently paused (read-only, managed by the system)
canPausebooleanfalseWhether this entity can be paused by the scene

Scene Events

Scenes now have pauseScene() and resumeScene() methods that emit out the pause state of the scene.

If you have UI elements, like a Pause Menu for example, that you want to respond to those events, you can listen to the scene's events emitter.