Skip to main content
The PlayState class is the core gameplay state where all rhythm gaming occurs. It manages the song, characters, stage, notes, scoring, health, and all gameplay mechanics.

Overview

PlayState is implemented as a MusicBeatSubState so it can be loaded as a child of the chart editor. It handles:
  • Song playback and synchronization
  • Note rendering and hit detection
  • Character animations and stage elements
  • Health and scoring systems
  • Input processing with latency compensation
  • Camera movement and effects
  • Cutscenes and dialogue

Accessing PlayState

PlayState.instance is null when not in gameplay. Always check for null before accessing.

Initialization

PlayStateParams

PlayState is initialized using a PlayStateParams typedef:
Song
required
The song to play.
String
default:"Constants.DEFAULT_DIFFICULTY"
The difficulty to play (e.g., “easy”, “normal”, “hard”).
String
default:"Constants.DEFAULT_VARIATION"
The chart variation to use.
String
Alternate instrumental ID if the song supports multiple instrumentals.
Bool
default:"false"
Whether to start in Practice Mode (no score/health penalty).
Bool
default:"false"
Whether to start in Bot Play Mode (auto-play).
Bool
default:"false"
If true, skips loading stage and characters, using a simple background.
Float
default:"0.0"
Start position in milliseconds. Used for practice and chart playtesting.
Float
default:"1.0"
Song playback speed multiplier (1.0 = 100% speed).
Example:

Key Properties

Song Properties

Song
The currently active song.
String
The currently selected difficulty.
String
The currently selected chart variation.
String
The currently selected instrumental ID.
Stage
The currently active stage with all props and characters.

Gameplay State

Float
Player’s current health (0-2 range, starts at 1.0).
Int
Player’s current score.
Float
Starting position in milliseconds when the countdown ends.
Float
Song playback speed multiplier (1.0 = 100%).
Bool
Whether Practice Mode is active.
Bool
Whether Bot Play Mode is active.
Bool
Whether Minimal Mode is active (no stage/characters).
Bool
Whether the countdown before the song is active.
Bool
Whether an animated cutscene is playing and gameplay is stopped.
Bool
Whether inputs are disabled (used after song ends or in stage editor).

Camera Properties

FlxObject
The object the gameplay camera follows. Tween this to move the camera smoothly.
Float
Current camera zoom level without modifiers applied.
Float
default:"1.015"
Camera bop intensity multiplier applied on beat hits.
Float
default:"4.0"
How many beats between camera zooms. Default is one zoom per measure (4 beats).

Audio Volume

Float
default:"1.0"
Volume of the instrumental track (0.0-1.0).
Float
default:"1.0"
Volume of the player vocals track (0.0-1.0).
Float
default:"1.0"
Volume of the opponent vocals track (0.0-1.0).

Key Methods

startCountdown()

Starts the countdown before the song begins.
Returns: The Countdown object that was created. Example:

endSong()

Ends the song and transitions to results or next song.
Bool
default:"false"
Whether to skip the end-of-song delay.

pauseGame()

Pauses the game and opens the pause menu.

resetCamera()

Resets the camera zoom and forces focus on the camera follow point.
Bool
default:"true"
Whether to reset zoom to the default stage zoom.
Bool
default:"true"
Whether to cancel any active camera tweens.

focusOnCharacter()

Moves the camera to focus on a specific character.
BaseCharacter
required
The character to focus on.
Bool
default:"true"
Whether to use the character’s midpoint for positioning.

Example: Custom Gameplay Mod

Example: Custom Camera Movement

Example: Accessing Stage Characters

Health System

Health ranges from 0.0 to 2.0, with 1.0 being the starting value:
  • Health < 0.0: Player dies (triggers game over)
  • Health = 1.0: Starting health (center of health bar)
  • Health > 2.0: Clamped to maximum
Health changes based on note hits:
  • Perfect hit: +0.023 health
  • Note miss: -0.0475 health
  • Ghost tap: Small penalty (configurable)

Volume Control

Control individual audio track volumes:

See Also