Overview
TheStage 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
Human-readable name of the stage
Default camera zoom level for this stage
Optional mask texture for shader effects
Methods
new(id:String, ?params:Dynamic)
Creates a new stage instance.
Stage ID matching the stage data JSON file
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.
The sprite to add to the stage
Optional unique name for later retrieval
addBopper(bopper:Bopper, ?name:String = null):Void
Adds an animated sprite that bops to the beat.
The bopper to add to the stage
Optional unique name for later retrieval
addCharacter(character:BaseCharacter, charType:CharacterType):Void
Adds a character to the stage with proper positioning and setup.
The character to add
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.
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
Event Dispatching
dispatchToCharacters(event:ScriptEvent):Void
Dispatches an event to all characters on the stage.
- Dad (opponent)
- Boyfriend (player)
- Girlfriend
- 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:Building Stages
ThebuildStage() 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
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).
