FlixelGraphic
View sourceclass
org.flixelgdx.graphics.FlixelGraphic
Reference-counted wrapper around a libGDX Texture, implementing FlixelAsset<FlixelGraphic>.
Graphics are shared: multiple sprites loading the same path get the same FlixelGraphic instance from FlixelAssetManager.get(String). Each user must call FlixelGraphic.retain() on the handle and FlixelGraphic.release() when done so the manager can track which textures are still in use and unload idle ones at state-switch time.
Use FlixelGraphic.getTexture() to access the underlying libGDX Texture. If the texture is not yet loaded it is fetched synchronously; queue the asset with FlixelAssetManager.load(String) in a loading state to avoid mid-frame stalls.
Owned vs path-keyed graphics
- Path-keyed - Created from a file path (e.g.
"images/player.png"). The texture is managed by the libGDXAssetManagerand unloaded when the reference count drops to zero and FlixelAssetManager.clearNonPersist() runs. - Owned - Created with a dedicated
Texture(e.g. from FlixelSprite.makeGraphic). The texture is disposed directly when the graphic is evicted. FlixelGraphic.isOwned() istrue.
Persist controls whether an unreferenced path-keyed graphic survives FlixelAssetManager.clearNonPersist(). Owned graphics always use persist = false and are evicted at refcount zero regardless.
Constructors
FlixelGraphic(FlixelAssetManager, String)
Creates a path-keyed graphic. The texture is loaded lazily from the libGDX AssetManager on the first FlixelGraphic.getTexture() call.
Parameters:
| Name | Description |
|---|---|
assets | The owning asset manager. |
path | Normalized asset path. |
FlixelGraphic(FlixelAssetManager, String, Texture)
Creates an owned graphic wrapping a dedicated texture (e.g. from a Pixmap). Pass null for ownedTexture to create a path-keyed graphic instead.
Parameters:
| Name | Description |
|---|---|
assets | The owning asset manager. |
path | Asset path or synthetic key. |
ownedTexture | The dedicated texture, or null for path-keyed loading. |
Methods
getPath()
get()
Returns this, since the graphic is its own handle.
isLoaded()
getLoaded()
Returns whether this graphic's texture has been loaded into memory.
isPersist()
getPersist()
Returns whether this graphic is marked to persist across state transitions.
setPersist(boolean)
getRefCount()
retain()
release()
getTexture()
Returns the underlying libGDX Texture. If the texture is not yet loaded, it is fetched synchronously. Prefer loading assets in a loading state to avoid stalls.
Returns: The texture; never null.
getResolvedPath()
Returns the path actually used to load the underlying texture from the libGDX AssetManager, resolved on demand through FlixelAssetManager.resolveTexturePath(String).
Equal to FlixelGraphic.getPath() unless a .ktx2 sibling was found for this graphic, in which case that sibling's path is returned instead.
Returns: The resolved texture path.
getOwnedTexture()
Returns the dedicated texture for owned graphics, or null for path-keyed ones.
Returns: The owned texture, or null.
isOwned()
Returns true if this graphic wraps a dedicated texture (e.g. from FlixelSprite.makeGraphic) that is disposed directly when the graphic is evicted.
Returns: true if owned.
getOwned()
Returns whether this graphic owns its texture and disposes it on eviction.