Skip to main content

FlixelGraphic

View source

class

org.flixelgdx.graphics.FlixelGraphic

public final class FlixelGraphic implements FlixelAsset<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

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)

public FlixelGraphic(FlixelAssetManager assets, String path)

Creates a path-keyed graphic. The texture is loaded lazily from the libGDX AssetManager on the first FlixelGraphic.getTexture() call.

Parameters:

NameDescription
assetsThe owning asset manager.
pathNormalized asset path.

FlixelGraphic(FlixelAssetManager, String, Texture)

public FlixelGraphic(FlixelAssetManager assets, String path, Texture ownedTexture)

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:

NameDescription
assetsThe owning asset manager.
pathAsset path or synthetic key.
ownedTextureThe dedicated texture, or null for path-keyed loading.

Methods

getPath()

public String getPath()

get()

public FlixelGraphic get()

Returns this, since the graphic is its own handle.


isLoaded()

public boolean isLoaded()

getLoaded()

public boolean getLoaded()

Returns whether this graphic's texture has been loaded into memory.


isPersist()

public boolean isPersist()

getPersist()

public boolean getPersist()

Returns whether this graphic is marked to persist across state transitions.


setPersist(boolean)

public FlixelGraphic setPersist(boolean persist)

getRefCount()

public int getRefCount()

retain()

public FlixelGraphic retain()

release()

public FlixelGraphic release()

getTexture()

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

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

public Texture getOwnedTexture()

Returns the dedicated texture for owned graphics, or null for path-keyed ones.

Returns: The owned texture, or null.


isOwned()

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

public boolean getOwned()

Returns whether this graphic owns its texture and disposes it on eviction.