Skip to main content

FlixelBasic

View source

class

org.flixelgdx.FlixelBasic

public abstract class FlixelBasic implements IFlixelBasic

The most generic Flixel object. Both FlixelObject and FlixelCamera extend this class. It has no size, position, or graphical data, only lifecycle flags and a unique ID. It implements IFlixelBasic, the full contract used by FlixelState and FlixelBasicGroup.

Prefer FlixelBasic.kill() when an object should stop updating and drawing but might be FlixelBasic.revive()d later (bullets, particles, pooled gameplay objects). Call FlixelBasic.destroy() when you are done with the instance for good: it clears lifecycle state and, in subclasses such as FlixelSprite, releases graphics and other resources. FlixelBasic.dispose() and FlixelBasic.reset() (for Pool) delegate to FlixelBasic.destroy(), which aligns with libGDX's Disposable expectations.

Lifecycle cheat sheet

SituationUseAvoid
Temporarily hide/disable; same object will spawn againFlixelBasic.kill() then later FlixelBasic.revive()FlixelBasic.destroy() (drops resources you may still want)
Reuse a "dead" slot in a FlixelBasicGroupFlixelBasicGroup.recycle() or FlixelBasic.revive() after FlixelBasic.kill()FlixelBasic.destroy() unless you truly discard the instance
Remove from group only; you still hold the referenceFlixelBasicGroup.remove / FlixelGroupable.detachAssuming the group calls FlixelBasic.destroy() for you (it does not)
Object leaves the game for good (state end, level unload, texture swap)FlixelBasic.destroy() (and remove from any group first if needed)FlixelBasic.kill() alone (resources may leak until something calls FlixelBasic.destroy())
Container shut down (FlixelBasicGroup.destroy(), FlixelState.destroy())Let the group/state call FlixelBasic.destroy() on each memberRelying on FlixelBasic.kill() for GPU/native cleanup
Returning instance to a libGDX Poolpool.free(object) (invokes FlixelBasic.reset() -> FlixelBasic.destroy())Expecting FlixelBasic.kill() to run pool reset logic

Constructors

FlixelBasic()

public FlixelBasic()

Fields

ID

public final int ID

A unique ID starting from 0 and increasing by 1 for each subsequent FlixelBasic created.


cameras

public FlixelCamera[] cameras

Cameras this object may render on. null or an empty array means every camera.


active

public boolean active

Controls whether FlixelBasic.update(float) is automatically called.


alive

public boolean alive

Whether this object is alive. FlixelBasic.kill() and FlixelBasic.revive() both flip this switch (along with FlixelBasic.exists).

See Also: .isExists


exists

public boolean exists

Controls whether FlixelBasic.update(float) and FlixelDrawable.draw(FlixelBatch) are automatically called.


visible

public boolean visible

Controls whether this object should be displayed on the screen.

See Also: .isVisible


Methods

update(float)

public void update(float elapsed)

Updates the logic of this FlixelBasic.

Override this function to update your object's position and appearance. This is where most game rules and behavioral code will go.

Parameters:

NameDescription
elapsedSeconds elapsed since the last frame.

draw(FlixelBatch)

public void draw(FlixelBatch batch)

Override this function to control how the object is drawn. Doing so is rarely necessary but can be very useful.

Parameters:

NameDescription
batchThe batch used for rendering.

isOnDrawCamera()

protected boolean isOnDrawCamera()

Whether this object should render in the current FlixelGame camera pass.


isExists()

public boolean isExists()

getExists()

public boolean getExists()

Returns whether this object exists in the world.


setExists(boolean)

public void setExists(boolean exists)

isActive()

public boolean isActive()

getActive()

public boolean getActive()

Returns whether this object is active and will be updated each frame.


setActive(boolean)

public void setActive(boolean active)

isVisible()

public boolean isVisible()

getVisible()

public boolean getVisible()

Returns whether this object is visible and will be drawn each frame.


setVisible(boolean)

public void setVisible(boolean visible)

toggleVisible()

public void toggleVisible()

isKilled()

public boolean isKilled()

getKilled()

public boolean getKilled()

Returns whether this object has been killed (i.e. does not exist).


setKilled(boolean)

public void setKilled(boolean killed)

toggleKilled()

public void toggleKilled()

destroy()

public void destroy()

Cleans up this object so it can be garbage-collected. A destroyed FlixelBasic should not be used anymore. Use FlixelBasic.kill() if you only want to disable it temporarily and FlixelBasic.revive() it later.

Override this function to clean up any resources used by this object, such as textures, fonts, sounds, etc.

This function is called automatically when FlixelBasic.dispose() or FlixelBasic.reset() is executed, so you don't need to call it manually.

See Also: .dispose, .reset


kill()

public void kill()

Flags this object as nonexistent and dead. Default behavior sets both FlixelBasic.alive and FlixelBasic.exists to false. Use FlixelBasic.revive() to bring it back.


revive()

public void revive()

Brings this object back to life by setting FlixelBasic.alive and FlixelBasic.exists to true.


dispose()

public final void dispose()

Automatically calls FlixelBasic.destroy(). Marked as final to prevent subclasses from overriding it, they should call FlixelBasic.destroy() instead.


reset()

public final void reset()

Automatically calls FlixelBasic.destroy(). Marked as final to prevent subclasses from overriding it, they should call FlixelBasic.destroy() instead.


toString()

public String toString()