FlixelBasic
View sourceclass
org.flixelgdx.FlixelBasic
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
| Situation | Use | Avoid |
|---|---|---|
| Temporarily hide/disable; same object will spawn again | FlixelBasic.kill() then later FlixelBasic.revive() | FlixelBasic.destroy() (drops resources you may still want) |
| Reuse a "dead" slot in a FlixelBasicGroup | FlixelBasicGroup.recycle() or FlixelBasic.revive() after FlixelBasic.kill() | FlixelBasic.destroy() unless you truly discard the instance |
| Remove from group only; you still hold the reference | FlixelBasicGroup.remove / FlixelGroupable.detach | Assuming 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 member | Relying on FlixelBasic.kill() for GPU/native cleanup |
Returning instance to a libGDX Pool | pool.free(object) (invokes FlixelBasic.reset() -> FlixelBasic.destroy()) | Expecting FlixelBasic.kill() to run pool reset logic |
Constructors
FlixelBasic()
Fields
ID
A unique ID starting from 0 and increasing by 1 for each subsequent FlixelBasic created.
cameras
Cameras this object may render on. null or an empty array means every camera.
active
Controls whether FlixelBasic.update(float) is automatically called.
alive
Whether this object is alive. FlixelBasic.kill() and FlixelBasic.revive() both flip this switch (along with FlixelBasic.exists).
See Also: .isExists
exists
Controls whether FlixelBasic.update(float) and FlixelDrawable.draw(FlixelBatch) are automatically called.
visible
Controls whether this object should be displayed on the screen.
See Also: .isVisible
Methods
update(float)
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:
| Name | Description |
|---|---|
elapsed | Seconds elapsed since the last frame. |
draw(FlixelBatch)
Override this function to control how the object is drawn. Doing so is rarely necessary but can be very useful.
Parameters:
| Name | Description |
|---|---|
batch | The batch used for rendering. |
isOnDrawCamera()
Whether this object should render in the current FlixelGame camera pass.
isExists()
getExists()
Returns whether this object exists in the world.
setExists(boolean)
isActive()
getActive()
Returns whether this object is active and will be updated each frame.
setActive(boolean)
isVisible()
getVisible()
Returns whether this object is visible and will be drawn each frame.
setVisible(boolean)
toggleVisible()
isKilled()
getKilled()
Returns whether this object has been killed (i.e. does not exist).
setKilled(boolean)
toggleKilled()
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.
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()
Brings this object back to life by setting FlixelBasic.alive and FlixelBasic.exists to true.
dispose()
Automatically calls FlixelBasic.destroy(). Marked as final to prevent subclasses from overriding it, they should call FlixelBasic.destroy() instead.
reset()
Automatically calls FlixelBasic.destroy(). Marked as final to prevent subclasses from overriding it, they should call FlixelBasic.destroy() instead.