Skip to main content

FlixelState

View source

class

org.flixelgdx.FlixelState

public abstract class FlixelState extends FlixelBasicGroup<IFlixelBasic> implements Screen

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()

protected FlixelState()

Creates a new state with no limit on member count.


FlixelState(int)

protected FlixelState(int maxSize)

Creates a new state with a maximum member count (0 means unlimited).

Parameters:

NameDescription
maxSizeMaximum members (0 = unlimited).

Fields

persistentUpdate

public boolean persistentUpdate

Should this state update its logic even when a substate is currently opened?


persistentDraw

public boolean persistentDraw

Should this state draw its members even when a substate is currently opened?


destroySubStates

public boolean 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()

protected IFlixelBasic createMemberForRecycle()

recycle()

public IFlixelBasic recycle()

show()

public void show()

render(float)

public void render(float delta)

create()

public void 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)

public void update(float elapsed)

Updates the logic of this state.

Parameters:

NameDescription
elapsedThe amount of time that's occurred since the last frame.

draw(FlixelBatch)

public void draw(FlixelBatch batch)

Draws this state's members onto the screen.

Parameters:

NameDescription
batchThe batch that's used to draw this state's members.

openSubState(FlixelSubState)

public void openSubState(FlixelSubState toOpen)

Opens a FlixelSubState on top of this state. If there is already an active substate, it will be closed first.

Parameters:

NameDescription
toOpenThe substate to open.

closeSubState()

public void closeSubState()

Closes the currently active substate, if one exists.


resetSubState()

public void resetSubState()

Reloads the current substate's parent reference. Called internally after state transitions to ensure the parent link is correct.


startOutro(Runnable)

public void startOutro(Runnable onOutroComplete)

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:

NameDescription
onOutroCompleteCallback to invoke when the outro is complete.

resize(int, int)

public void resize(int width, int height)

pause()

public final void pause()

Do not override this method. Override FlixelState.onFocusLost() instead.


resume()

public final void resume()

Do not override this method. Override FlixelState.onFocusGained() instead.


onFocusLost()

public void 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()

public void 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()

public void 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()

public void hide()

destroy()

public void destroy()

add(IFlixelBasic)

public void add(IFlixelBasic basic)

Adds a new member to this state.

Parameters:

NameDescription
basicThe new member to add to the state.

getSubState()

public FlixelSubState getSubState()

getBgColor()

public Color getBgColor()

Reads the first camera's FlixelCamera.bgColor.

Returns: The background color of the first camera.


setBgColor(Color)

public void setBgColor(Color value)

Assigns every listed camera's FlixelCamera.bgColor.

Parameters:

NameDescription
valueThe background color to set.

toString()

public String toString()