Skip to main content

Overview

The Stage class manages the visual environment for gameplay, including background elements (props), character positioning, and camera settings. Stages are composed of one or more props that can be static or animated.

Class Hierarchy

Stage

Properties

String
Human-readable name of the stage
Float
Default camera zoom level for this stage
BitmapData
Optional mask texture for shader effects

Methods

new(id:String, ?params:Dynamic)

Creates a new stage instance.
String
required
Stage ID matching the stage data JSON file
Dynamic
Optional parameters for stage initialization

onCreate(event:ScriptEvent):Void

Called when entering PlayState. Builds all props and sets up the stage.

addProp(prop:StageProp, ?name:String = null):Void

Adds a sprite to the stage.
StageProp
required
The sprite to add to the stage
String
Optional unique name for later retrieval

addBopper(bopper:Bopper, ?name:String = null):Void

Adds an animated sprite that bops to the beat.
Bopper
required
The bopper to add to the stage
String
Optional unique name for later retrieval

addCharacter(character:BaseCharacter, charType:CharacterType):Void

Adds a character to the stage with proper positioning and setup.
BaseCharacter
required
The character to add
CharacterType
required
Character type (BF, DAD, GF, or OTHER)

getNamedProp(name:String):StageProp

Retrieves a prop by its assigned name.

getBoyfriend(pop:Bool = false):BaseCharacter

Retrieves the Boyfriend character.
Bool
default:"false"
If true, removes the character from the stage

getDad(pop:Bool = false):BaseCharacter

Retrieves the Dad/opponent character.

getGirlfriend(pop:Bool = false):BaseCharacter

Retrieves the Girlfriend character.

getCharacter(id:String):BaseCharacter

Retrieves a character by ID.

refresh():Void

Refreshes the stage by sorting all props by z-index.

resetStage():Void

Resets all characters and props to their original positions.

pause():Void

Pauses all animations in the stage.

resume():Void

Resumes all animations in the stage.

setShader(shader:FlxShader):Void

Applies a shader to all props in the stage.

Character Positioning

Position Methods

These return the positions defined in the stage data JSON, useful for custom positioning logic.

Event Dispatching

dispatchToCharacters(event:ScriptEvent):Void

Dispatches an event to all characters on the stage.
Characters receive events in this order:
  1. Dad (opponent)
  2. Boyfriend (player)
  3. Girlfriend
  4. Any other characters

dispatchToCharacter(characterId:String, event:ScriptEvent):Void

Dispatches an event to a specific character.

Stage Props

Prop Types

Stages can contain different types of props: Static Props:
Animated Props (Boppers):
Solid Color Props:

Building Stages

The buildStage() method automatically constructs the stage from JSON data:

Prop Properties from Data

  • Position: [x, y] coordinates
  • Scale: Uniform or [scaleX, scaleY]
  • Scroll Factor: [x, y] for parallax
  • Z-Index: Rendering order
  • Animations: Frame-based or atlas animations
  • Visual: alpha, angle, color, blend mode

Event Handlers

onStepHit(event:SongTimeScriptEvent):Void

Called every step of the song.

onBeatHit(event:SongTimeScriptEvent):Void

Called every beat of the song.

onUpdate(event:UpdateScriptEvent)

Called every frame.

onDestroy(event:ScriptEvent):Void

Called when leaving PlayState.

Usage Example

Frame Buffers

Stages support frame buffer effects for advanced rendering:

Best Practices

Always call refresh() after modifying z-index values to ensure correct rendering order.
Characters are positioned relative to their feet (bottom-center). Stage data should specify the floor position, not the top-left corner.
Use scroll factors for parallax effects. Values less than 1.0 make props scroll slower (appear further away), while values greater than 1.0 make them scroll faster (appear closer).