FlixelState
View sourceclass
org.flixelgdx.FlixelState
The core building block for every FlixelGDX game.
A state is a collection of IFlixelBasic objects that can be used for any important part of your game. This can be a level, a menu, or anything else.
Members are not pooled by the engine: FlixelState.remove only unlinks objects. Prefer FlixelBasic.kill() / FlixelBasic.revive() or FlixelBasicGroup.recycle() for reuse. FlixelState.createMemberForRecycle() supplies new FlixelSprite instances when FlixelBasicGroup.recycle() has no dead member to revive. Override it if your state recycles another IFlixelBasic implementation.
A state can open a FlixelSubState on top of itself. By default, when a substate is active the parent state will continue to be drawn (FlixelState.persistentDraw = true) but will stop updating (FlixelState.persistentUpdate = false).
See Also: IFlixelBasic, FlixelBasic, FlixelBasicGroup
Constructors
FlixelState()
Creates a new state with no limit on member count.
FlixelState(int)
Creates a new state with a maximum member count (0 means unlimited).
Parameters:
| Name | Description |
|---|---|
maxSize | Maximum members (0 = unlimited). |
Fields
persistentUpdate
Should this state update its logic even when a substate is currently opened?
persistentDraw
Should this state draw its members even when a substate is currently opened?
destroySubStates
If substates get destroyed when they are closed. Setting this to false might reduce state creation time, at the cost of greater memory usage.
Methods
createMemberForRecycle()
recycle()
show()
render(float)
create()
Called when the state is first created. This is where you want to assign your sprites and set up everything your state uses.
Make sure to override this, NOT the constructor!
update(float)
Updates the logic of this state.
Parameters:
| Name | Description |
|---|---|
elapsed | The amount of time that's occurred since the last frame. |
draw(FlixelBatch)
Draws this state's members onto the screen.
Parameters:
| Name | Description |
|---|---|
batch | The batch that's used to draw this state's members. |
openSubState(FlixelSubState)
Opens a FlixelSubState on top of this state. If there is already an active substate, it will be closed first.
Parameters:
| Name | Description |
|---|---|
toOpen | The substate to open. |
closeSubState()
Closes the currently active substate, if one exists.
resetSubState()
Reloads the current substate's parent reference. Called internally after state transitions to ensure the parent link is correct.
startOutro(Runnable)
Called from Flixel.switchState(FlixelState) before the actual state switch happens. Override this to play an exit animation or transition, then call onOutroComplete when finished.
The default implementation calls onOutroComplete immediately.
Parameters:
| Name | Description |
|---|---|
onOutroComplete | Callback to invoke when the outro is complete. |
resize(int, int)
pause()
Do not override this method. Override FlixelState.onFocusLost() instead.
resume()
Do not override this method. Override FlixelState.onFocusGained() instead.
onFocusLost()
Called when the game window loses focus or the application goes to the background.
Override this to react to focus loss in your state. The default implementation walks down to the active FlixelSubState so it is also notified.
See Also: FlixelGame.onFocusLost
onFocusGained()
Called when the game window regains focus or the application returns to the foreground.
Override this to react to focus gain in your state. The default implementation walks down to the active FlixelSubState so it is also notified.
See Also: FlixelGame.onFocusGained
onMinimized()
Called when the desktop window is minimized.
This is a desktop-only event; it is never called on mobile or web platforms. The default implementation walks down to the active FlixelSubState so it is also notified.
See Also: FlixelGame.onMinimized
hide()
destroy()
add(IFlixelBasic)
Adds a new member to this state.
Parameters:
| Name | Description |
|---|---|
basic | The new member to add to the state. |
getSubState()
getBgColor()
Reads the first camera's FlixelCamera.bgColor.
Returns: The background color of the first camera.
setBgColor(Color)
Assigns every listed camera's FlixelCamera.bgColor.
Parameters:
| Name | Description |
|---|---|
value | The background color to set. |