The gameplay state, where all the rhythm gaming happens. SubState so it can be loaded as a child of the chart editor.

Static variables

staticinstance:Null<PlayState>

The currently active PlayState. There should be only one PlayState in existance at a time, we can use a singleton.

Constructor

new(?params:Null<PlayStateParams>)

Instantiate a new PlayState.

Parameters:

params

The parameters used to initialize the PlayState. Includes information about what song to play and more.

Variables

camCutouts:FlxCamera

The camera which contains, and controls visibility of menus when there are fake cutouts added.

camCutscene:FlxCamera

The camera which contains, and controls visibility of, a video cutscene, dialogue.

camGame:FlxCamera

The camera which contains, and controls visibility of, the stage and characters.

camHUD:FlxCamera

The camera which contains, and controls visibility of, the user interface elements.

camPause:FlxCamera

The camera which contains, and controls visibility of, pause menu.

camSubtitles:FlxCamera

The camera which contains, and controls visibility of, the subtitles.

@:value(Constants.DEFAULT_BOP_INTENSITY)cameraBopIntensity:Float = Constants.DEFAULT_BOP_INTENSITY

Camera bop intensity multiplier. Applied to cameraBopMultiplier on camera bops (usually every beat).

@:value(1.0)cameraBopMultiplier:Float = 1.0

Multiplier for currentCameraZoom for camera bops. Lerped back to 1.0x every frame.

cameraFollowPoint:FlxObject

An empty FlxObject contained in the scene. The current gameplay camera will always follow this object. Tween its position to move the camera smoothly.

It needs to be an object in the scene for the camera to be configured to follow it. We optionally make this a sprite so we can draw a debug graphic with it.

cameraFollowTween:Null<FlxTween>

An FlxTween that tweens the camera to the follow point. Only used when tweening the camera manually, rather than tweening via follow.

@:value(Constants.DEFAULT_ZOOM_RATE)cameraZoomRate:Int = Constants.DEFAULT_ZOOM_RATE

How many beats (quarter notes) between camera zooms.

@:value(Constants.DEFAULT_ZOOM_OFFSET)cameraZoomRateOffset:Int = Constants.DEFAULT_ZOOM_OFFSET

How many beats (quarter notes) the zoom rate is offset. For if you want the zoom to happen off-beat.

cameraZoomTween:Null<FlxTween>

An FlxTween that zooms the camera to the desired amount.

comboPopUps:PopUpStuff

The combo popups. Includes the real-time combo counter and the rating.

@:value(FlxCamera.defaultZoom)currentCameraZoom:Float = FlxCamera.defaultZoom

The current camera zoom level without any modifiers applied.

read onlycurrentChart:Null<SongDifficulty>

Data for the current difficulty for the current song. Includes chart data, scroll speed, and other information.

currentConversation:Null<Conversation>

The current dialogue.

@:value(Constants.DEFAULT_DIFFICULTY)currentDifficulty:String = Constants.DEFAULT_DIFFICULTY

The currently selected difficulty.

@:value("")currentInstrumental:String = ""

The currently selected instrumental ID.

currentSong:Song

The currently selected stage.

@:value(null)currentStage:Null<Stage> = null

The currently active Stage. This is the object containing all the props.

read onlycurrentStageId:String

The internal ID of the currently active Stage. Used to retrieve the data required to build the currentStage.

@:value(Constants.DEFAULT_VARIATION)currentVariation:String = Constants.DEFAULT_VARIATION

The currently selected variation.

@:value(0)deathCounter:Int = 0

The current 'Blueball Counter' to display in the pause menu. Resets when you beat a song or go back to the main menu.

@:value(false)debugUnbindCameraZoom:Bool = false

Simple helper debug variable, to be able to move the camera around for debug purposes without worrying about the camera tweening back to the follow point.

@:value(FlxCamera.defaultZoom * 1.0)defaultHUDCameraZoom:Float = FlxCamera.defaultZoom * 1.0

The current HUD camera zoom level.

The camera zoom is increased every beat, and lerped back to this value every frame, creating a smooth 'zoom-in' effect.

@:value(false)disableKeys:Bool = false

Whether the inputs should be disabled for whatever reason... Used after the song ends, and in the Stage Editor.

@:value(Constants.HEALTH_STARTING)health:Float = Constants.HEALTH_STARTING

The player's current health.

healthBar:FlxBar

The bar which displays the player's health. Dynamically updated based on the value of healthLerp (which is based on health).

healthBarBG:FunkinSprite

The background image used for the health bar. Emma says the image is slightly skewed so I'm leaving it as an image instead of a createGraphic.

@:value(0.015 * 2.0)hudCameraZoomIntensity:Float = 0.015 * 2.0

Intensity of the HUD camera zoom. Need to make this a multiplier later. Just shoving in 0.015 for now so it doesn't break.

iconP1:Null<HealthIcon>

The health icon representing the player.

iconP2:Null<HealthIcon>

The health icon representing the opponent.

@:value(1.0)instrumentalVolume:Float = 1.0

The volume of the instrumental track.

@:value(false)isBotPlayMode:Bool = false

Whether the game is currently in Bot Play Mode. If true, player will not gain or lose score from notes.

read onlyisChartingMode:Bool

@:value(false)isGameOverState:Bool = false

Whether the game is currently in the Game Over state.

@:value(false)isInCountdown:Bool = false

Whether the game is currently in the countdown before the song resumes.

@:value(false)isInCutscene:Bool = false

Whether the game is currently in an animated cutscene, and gameplay should be stopped.

@:value(false)isMinimalMode:Bool = false

In Minimal Mode, the stage and characters are not loaded and a standard background is used.

@:value(false)isPlayerDying:Bool = false

Whether the player has dropped below zero health, and we are just waiting for an animation to play out before transitioning.

@:value(false)isPlaytestResults:Bool = false

Whether the results screen should show up before returning to the chart editor.

@:value(false)isPracticeMode:Bool = false

Whether the game is currently in Practice Mode. If true, player will not gain or lose score from notes.

@:value(false)isSongEnd:Bool = false

read onlyisSubState:Bool

@:value(false)needsReset:Bool = false

Gets set to true when the PlayState needs to reset (player opted to restart or died). Gets disabled once resetting happens.

opponentStrumline:Strumline

The sprite group containing opponent's strumline notes.

@:value(1.0)opponentVocalsVolume:Float = 1.0

The volume of the opponent vocals track.

@:value(1.0)playbackRate:Float = 1.0

Play back the song at this speed.

playerStrumline:Strumline

The sprite group containing active player's strumline notes.

@:value(1.0)playerVocalsVolume:Float = 1.0

The volume of the player vocals track.

previousCameraFollowPoint:Null<FlxPoint>

The camera follow point from the last stage. Used to persist the position of the cameraFollowPosition between levels.

@:value(Constants.DEFAULT_DIFFICULTY)previousDifficulty:String = Constants.DEFAULT_DIFFICULTY

The previous difficulty the player was playing on.

@:value([])scrollSpeedTweens:Array<FlxTween> = []

An FlxTween that changes the additive speed to the desired amount.

@:value(false)shouldSubstatePause:Bool = false

Determines whether opening a substate over this causes the game to pause. Enable it before opening a Pause menu or Game Over screen, and disable it for stuff like editors and overlays.

@:value(0)songScore:Int = 0

The player's current score. TODO: Move this to its own class.

read onlystageZoom:Float

Default camera zoom for the current stage. If we aren't in a stage, just use the default zoom (1.05x).

@:value(0.0)startTimestamp:Float = 0.0

Start at this point in the song once the countdown is done. For example, if startTimestamp is 30000, the song will start at the 30 second mark. Used for chart playtesting or practice.

subtitles:Null<Subtitles>

A sprite group for subtitle display.

vocals:Null<VoicesGroup>

A group of audio tracks, used to play the song's vocals.

@:value(new FlxTimer())vwooshTimer:FlxTimer = new FlxTimer()

A timer that gets active once resetting happens. Used to vwoosh in notes.

Methods

cancelAllCameraTweens():Void

Cancel all active camera tweens simultaneously.

closeSubState():Void

Function called before closing the current substate.

Parameters:

null

subState

@:nullSafety(Off)create():Void

Called when the PlayState is switched to.

@:value({ rightGoddamnNow : false })endSong(rightGoddamnNow:Bool = false):Void

End the song. Handle saving high scores and transitioning to the results screen.

Broadcasts an onSongEnd event, which can be cancelled to prevent the song from ending (for a cutscene or something). Remember to call endSong again when the song should actually end!

Parameters:

rightGoddamnNow

If true, don't play the fancy animation where you zoom onto Girlfriend. Used after a cutscene.

onFocus():Void

Function called when the game window gains focus.

onFocusLost():Void

Function called when the game window loses focus.

openSubState(subState:FlxSubState):Void

Function called before opening a new substate.

Parameters:

subState

The substate to open.

pauseMusic():Void

Pauses music and vocals easily.

@:value({ snap : true, cancelTweens : true, resetZoom : true })resetCamera(resetZoom:Bool = true, cancelTweens:Bool = true, snap:Bool = true):Void

Resets the camera's zoom level and focus point.

startConversation(conversationId:String):Void

Displays a dialogue cutscene with the given ID. This is used by song scripts to display dialogue.

startCountdown():Void

Prepares to start the countdown. Ends any running cutscenes, creates the strumlines, and starts the countdown. This is public so that scripts can call it.

@:value({ visible : false })togglePauseButton(visible:Bool = false):Void

@:value({ duration : 0 })tweenCameraToFollowPoint(duration:Float = 0, ?ease:Float ‑> Float):Void

Disables camera following and tweens the camera to the follow point manually.

@:value({ duration : 0, y : 0, x : 0 })tweenCameraToPosition(x:Float = 0, y:Float = 0, duration:Float = 0, ?ease:Float ‑> Float):Void

Sets the camera follow point's position and tweens the camera there.

@:value({ direct : false, duration : 0, zoom : 1 })tweenCameraZoom(zoom:Float = 1, duration:Float = 0, direct:Bool = false, ?ease:Float ‑> Float):Void

Tweens the camera zoom to the desired amount.

tweenScrollSpeed(?speed:Float, ?duration:Float, ?ease:Float ‑> Float, strumlines:Array<String>):Void

The magical function that shall tween the scroll speed.

Inherited Variables

Defined by MusicBeatSubState

@:value(null)leftWatermarkText:Null<FlxText> = null

@:value(null)rightWatermarkText:Null<FlxText> = null

Defined by FlxSubState

closeCallback:() ‑> Void

Callback method for state close event.

openCallback:() ‑> Void

Callback method for state open/resume event.

Available since

4.3.0

.

Defined by FlxState

bgColor:FlxColor

The natural background color the cameras default to. In AARRGGBB format.

@:value(true)destroySubStates:Bool = true

If substates get destroyed when they are closed, setting this to false might reduce state creation time, at greater memory cost.

@:value(true)persistentDraw:Bool = true

Determines whether the current state is drawn, even when it is not the active state. For example, if you have your game state open first, and then you push a pause state on top of it, if this is set to true, the game state would still continue to be drawn behind that pause state.

By default, this is set to true, so the background states will continue to be "drawn" behind the current state.

If you do not want background states to be visible when you have a different state on top, then you should set this to false for improved performance.

@:value(false)persistentUpdate:Bool = false

Determines whether the current state is updated, even when it is not the active state. For example, if you have your game state open first, and then you push a pause state on top of it, if this is set to true, the game state would still continue to be updated in the background.

By default, this is set to false, so the background states will continue to be "paused" when they are not active.

read onlysubState:FlxSubState

Current substate. Substates also can be nested.

read onlysubStateClosed:FlxTypedSignal<FlxSubState ‑> Void>

A FlxSignal that dispatches when a sub state is closed from this state.

Available since

4.9.0

.

read onlysubStateOpened:FlxTypedSignal<FlxSubState ‑> Void>

A FlxSignal that dispatches when a sub state is opened from this state.

Available since

4.9.0

.

Defined by FlxTypedGroup

@:value(0)read onlylength:Int = 0

The number of entries in the members array. For performance and safety you should check this variable instead of members.length unless you really know what you're doing!

maxSize:Int

The maximum capacity of this group. Default is 0, meaning no max capacity, and the group can just grow.

read onlymemberAdded:FlxTypedSignal<T ‑> Void>

A FlxSignal that dispatches when a child is added to this group.

Available since

4.4.0

.

read onlymemberRemoved:FlxTypedSignal<T ‑> Void>

A FlxSignal that dispatches when a child is removed from this group.

Available since

4.4.0

.

read onlymembers:Array<T>

Array of all the members in this group.

Defined by FlxBasic

@:value(idEnumerator++)ID:Int = idEnumerator++

A unique ID starting from 0 and increasing by 1 for each subsequent FlxBasic that is created.

@:value(true)active:Bool = true

Controls whether update() is automatically called by FlxState/FlxGroup.

@:value(true)alive:Bool = true

Useful state for many game objects - "dead" (!alive) vs alive. kill() and revive() both flip this switch (along with exists, but you can override that).

camera:FlxCamera

Gets or sets the first camera of this object.

cameras:Array<FlxCamera>

This determines on which FlxCameras this object will be drawn. If it is null / has not been set, it uses the list of default draw targets, which is controlled via FlxG.camera.setDefaultDrawTarget as well as the DefaultDrawTarget argument of FlxG.camera.add.

read onlycontainer:Null<FlxContainer>

The parent containing this basic, typically if you check this recursively you should reach the state

Available since

5.7.0

.

@:value(true)exists:Bool = true

Controls whether update() and draw() are automatically called by FlxState/FlxGroup.

@:value(true)visible:Bool = true

Controls whether draw() is automatically called by FlxState/FlxGroup.

@:value(0)zIndex:Int = 0

Inherited Methods

Defined by MusicBeatSubState

refresh():Void

Refreshes the state, by redoing the render order of all sprites. It does this based on the zIndex of each prop.

switchSubState(substate:FlxSubState):Void

Close this substate and replace it with a different one.

Defined by FlxSubState

Defined by FlxState

onResize(Width:Int, Height:Int):Void

This function is called whenever the window size has been changed.

Parameters:

Width

The new window width

Height

The new window Height

resetSubState():Void

Load substate for this state

Defined by FlxTypedGroup

add(basic:T):T

Adds a new FlxBasic subclass (FlxBasic, FlxSprite, Enemy, etc) to the group. FlxGroup will try to replace a null member of the array first. Failing that, FlxGroup will add it to the end of the member array. WARNING: If the group has a maxSize that has already been met, the object will NOT be added to the group!

Parameters:

basic

The FlxBasic you want to add to the group.

Returns:

The same FlxBasic object that was passed in.

any(func:T ‑> Bool):Bool

Tests whether any member satisfies the function.

Parameters:

func

The function that tests the members

Available since

5.4.0

.

clear():Void

Remove all instances of FlxBasic subclasses (FlxSprite, FlxTileblock, etc) from the list. WARNING: does not destroy() or kill() any of these objects!

countDead():Int

Call this function to find out how many members of the group are dead.

Returns:

The number of FlxBasics flagged as dead. Returns -1 if group is empty.

countLiving():Int

Call this function to find out how many members of the group are not dead.

Returns:

The number of FlxBasics flagged as not dead. Returns -1 if group is empty.

every(func:T ‑> Bool):Bool

Tests whether every member satisfies the function.

Parameters:

func

The function that tests the members

Available since

5.4.0

.

@:value({ recurse : false })forEach(func:T ‑> Void, recurse:Bool = false):Void

Applies a function to all members.

Parameters:

func

A function that modifies one element at a time.

recurse

Whether or not to apply the function to members of subgroups as well.

@:value({ recurse : false })forEachAlive(func:T ‑> Void, recurse:Bool = false):Void

Applies a function to all alive members.

Parameters:

func

A function that modifies one element at a time.

recurse

Whether or not to apply the function to members of subgroups as well.

@:value({ recurse : false })forEachDead(func:T ‑> Void, recurse:Bool = false):Void

Applies a function to all dead members.

Parameters:

func

A function that modifies one element at a time.

recurse

Whether or not to apply the function to members of subgroups as well.

@:value({ recurse : false })forEachExists(func:T ‑> Void, recurse:Bool = false):Void

Applies a function to all existing members.

Parameters:

func

A function that modifies one element at a time.

recurse

Whether or not to apply the function to members of subgroups as well.

@:value({ recurse : false })forEachOfType<K>(objectClass:Class<K>, func:K ‑> Void, recurse:Bool = false):Void

Applies a function to all members of type Class<K>.

Parameters:

objectClass

A class that objects will be checked against before Function is applied, ex: FlxSprite.

func

A function that modifies one element at a time.

recurse

Whether or not to apply the function to members of subgroups as well.

getFirst(func:T ‑> Bool):Null<T>

Searches for, and returns the first member that satisfies the function.

Parameters:

func

The function that tests the members

Available since

5.4.0

.

getFirstAlive():Null<T>

Call this function to retrieve the first object with dead == false in the group. This is handy for checking if everything's wiped out, or choosing a squad leader, etc.

Returns:

A FlxBasic currently flagged as not dead.

@:value({ force : false })getFirstAvailable(?objectClass:Class<T>, force:Bool = false):Null<T>

Call this function to retrieve the first object with exists == false in the group. This is handy for recycling in general, e.g. respawning enemies.

Parameters:

objectClass

An optional parameter that lets you narrow the results to instances of this particular class.

force

Force the object to be an ObjectClass and not a super class of ObjectClass.

Returns:

A FlxBasic currently flagged as not existing.

getFirstDead():Null<T>

Call this function to retrieve the first object with dead == true in the group. This is handy for checking if everything's wiped out, or choosing a squad leader, etc.

Returns:

A FlxBasic currently flagged as dead.

getFirstExisting():Null<T>

Call this function to retrieve the first object with exists == true in the group. This is handy for checking if everything's wiped out, or choosing a squad leader, etc.

Returns:

A FlxBasic currently flagged as existing.

getFirstIndex(func:T ‑> Bool):Int

Searches for, and returns the index of the first member that satisfies the function.

Parameters:

func

The function that tests the members

Available since

5.4.0

.

getFirstNull():Int

Call this function to retrieve the first index set to null. Returns -1 if no index stores a null object.

Returns:

An Int indicating the first null slot in the group.

getLast(func:T ‑> Bool):Null<T>

Searches for, and returns the last member that satisfies the function.

Parameters:

func

The function that tests the members

Available since

5.4.0

.

getLastIndex(func:T ‑> Bool):Int

Searches for, and returns the index of the last member that satisfies the function.

Parameters:

func

The function that tests the members

Available since

5.4.0

.

@:value({ length : 0, startIndex : 0 })getRandom(startIndex:Int = 0, length:Int = 0):T

Returns a member at random from the group.

Parameters:

startIndex

Optional offset off the front of the array. Default value is 0, or the beginning of the array.

length

Optional restriction on the number of values you want to randomly select from.

Returns:

A FlxBasic from the members list.

insert(position:Int, object:T):T

Inserts a new FlxBasic subclass (FlxBasic, FlxSprite, Enemy, etc) into the group at the specified position. FlxGroup will try to replace a null member at the specified position of the array first. Failing that, FlxGroup will insert it at the position of the member array. WARNING: If the group has a maxSize that has already been met, the object will NOT be inserted to the group!

Parameters:

position

The position in the group where you want to insert the object.

object

The object you want to insert into the group.

Returns:

The same FlxBasic object that was passed in.

inlineiterator(?filter:T ‑> Bool):FlxTypedGroupIterator<T>

Iterates through every member.

inlinekeyValueIterator():ArrayKeyValueIterator<T>

Iterates through every member and index.

kill():Void

Calls killMembers() and then kills the group itself. Revive this group via revive().

killMembers():Void

Calls kill() on the group's unkilled members. Revive them via reviveMembers().

Available since

5.4.0

.

@:value({ revive : true, force : false })recycle(?objectClass:Class<T>, ?objectFactory:() ‑> T, force:Bool = false, revive:Bool = true):T

Recycling is designed to help you reuse game objects without always re-allocating or "newing" them. It behaves differently depending on whether maxSize equals 0 or is bigger than 0.

maxSize > 0 / "rotating-recycling" (used by FlxEmitter): - at capacity: returns the next object in line, no matter its properties like alive, exists etc. - otherwise: returns a new object.

maxSize == 0 / "grow-style-recycling" - tries to find the first object with exists == false - otherwise: adds a new object to the members array

WARNING: If this function needs to create a new object, and no object class was provided, it will return null instead of a valid object!

Parameters:

objectClass

The class type you want to recycle (e.g. FlxSprite, EvilRobot, etc).

objectFactory

Optional factory function to create a new object if there aren't any dead members to recycle. If null, Type.createInstance() is used, which requires the class to have no constructor parameters.

force

Force the object to be an ObjectClass and not a super class of ObjectClass.

revive

Whether recycled members should automatically be revived (by calling revive() on them).

Returns:

A reference to the object that was created.

@:value({ splice : false })remove(basic:T, splice:Bool = false):T

Removes an object from the group.

Parameters:

basic

The FlxBasic you want to remove.

splice

Whether the object should be cut from the array entirely or not.

Returns:

The removed object.

replace(oldObject:T, newObject:T):T

Replaces an existing FlxBasic with a new one. Does not do anything and returns null if the old object is not part of the group.

Parameters:

oldObject

The object you want to replace.

newObject

The new object you want to use instead.

Returns:

The new object.

revive():Void

Calls reviveMembers() and then revives the group itself.

reviveMembers():Void

Calls revive() on the group's killed members and then on the group itself.

Available since

5.4.0

.

@:value({ order : FlxSort.ASCENDING })inlinesort(func:(Int, T, T) ‑> Int, order:Int = FlxSort.ASCENDING):Void

Call this function to sort the group according to a particular value and order. For example, to sort game objects for Zelda-style overlaps you might call group.sort(FlxSort.byY, FlxSort.ASCENDING) at the bottom of your FlxState#update() override.

Parameters:

func

The sorting function to use - you can use one of the premade ones in FlxSort or write your own using FlxSort.byValues() as a "backend".

order

A constant that defines the sort order. Possible values are FlxSort.ASCENDING (default) and FlxSort.DESCENDING.

Defined by FlxBasic

getCameras():Array<FlxCamera>

The cameras that will draw this. Use this.cameras to set specific cameras for this object, otherwise the container's cameras are used, or the container's container and so on. If there is no container, say, if this is inside FlxGroups rather than a FlxContainer then the default draw cameras are returned.

Available since

5.7.0

.

getDefaultCamera():FlxCamera

The main camera that will draw this. Use this.cameras to set specific cameras for this object, otherwise the container's camera is used, or the container's container and so on. If there is no container, say, if this is inside FlxGroups rather than a FlxContainer then FlxG.camera is returned.

Available since

5.7.0

.

toString():String