FlixelSpriteUtil
View sourceclass
org.flixelgdx.util.FlixelSpriteUtil
Helper class related to FlixelSprite.
These utilities are designed to work with FlixelGDX's normal Batch-based draw flow. Avoid using ShapeRenderer in core game rendering unless you control the render pipeline.
Do not call FlixelSpriteUtil.createWhitePixelTexture() every frame or per sprite instance in hot paths. That allocates new Pixmap and Texture objects and will spike heap usage on most JVMs. Prefer FlixelSpriteUtil.obtainWhitePixelTexture(FlixelAssetManager), which registers a single persistent texture with the asset manager (see FlixelDefaultAssetManager) and reuses it for the lifetime of the game.
FlixelSpriteUtil.fill(FlixelSprite, Color) writes solid pixels into the active frame when possible, and FlixelSpriteUtil.setBrightness(FlixelSprite, float) adjusts tint like Animate brightness.
Fields
WHITE_PIXEL_TEXTURE_KEY
Fixed asset key for the framework-owned 1x1 white Texture registered via FlixelSpriteUtil.obtainWhitePixelTexture(FlixelAssetManager).
Methods
obtainWhitePixelTexture(FlixelAssetManager)
Returns the shared 1x1 white Texture registered with assets. The first call creates the texture, wraps it in a FlixelGraphic with FlixelGraphic.setPersist(boolean) true, and registers it with FlixelAssetManager.register(FlixelAsset<?>). Callers must not Texture.dispose() this texture; lifecycle follows the asset manager.
Parameters:
| Name | Description |
|---|---|
assets | Non-null manager from Flixel.ensureAssets(). |
createWhitePixelTexture()
Creates a 1x1 white pixel texture.
Ownership: Prefer FlixelSpriteUtil.obtainWhitePixelTexture(FlixelAssetManager) so only one instance exists. If you call this directly, you own the returned texture and must dispose it.
Returns: The created white pixel texture.
drawRect(Batch, Texture, float, float, float, float, Color)
Draws a rectangle with the given color.
Parameters:
| Name | Description |
|---|---|
batch | The batch to draw the rectangle on. |
whitePixel | The white pixel texture to use for the rectangle. |
x | The x position of the rectangle. |
y | The y position of the rectangle. |
w | The width of the rectangle. |
h | The height of the rectangle. |
color | The color of the rectangle. |
drawBorder(Batch, Texture, float, float, float, float, float, Color)
Draws a border around the given rectangle.
Parameters:
| Name | Description |
|---|---|
batch | The batch to draw the border on. |
whitePixel | The white pixel texture to use for the border. |
x | The x position of the rectangle. |
y | The y position of the rectangle. |
w | The width of the rectangle. |
h | The height of the rectangle. |
thickness | The thickness of the border. |
color | The color of the border. |
createLinearGradientPixmap(int, int, Color, Color, boolean)
Creates a 2-color linear gradient Pixmap.
Caller owns the returned Pixmap and must dispose of it through Pixmap.dispose() themselves.
Parameters:
| Name | Description |
|---|---|
width | The width of the gradient. |
height | The height of the gradient. |
start | The start color of the gradient. |
end | The end color of the gradient. |
horizontal | Whether the gradient is horizontal. |
Returns: The created gradient Pixmap.
createLinearGradientTexture(int, int, Color, Color, boolean)
Creates a 2-color linear gradient Texture.
Caller owns the returned Texture and must dispose of it through Texture.dispose() themselves.
Parameters:
| Name | Description |
|---|---|
width | The width of the gradient. |
height | The height of the gradient. |
start | The start color of the gradient. |
end | The end color of the gradient. |
horizontal | Whether the gradient is horizontal. |
Returns: The created gradient Texture.
bound(FlixelSprite, float, float, float, float)
Clamps the sprite inside a world rectangle. When maxX or maxY are 0 or less, the game view size from Flixel.getWidth() / Flixel.getHeight() is used for that axis.
Parameters:
| Name | Description |
|---|---|
sprite | The sprite to bound. |
minX | The minimum x position. |
maxX | The maximum x position. |
minY | The minimum y position. |
maxY | The maximum y position. |
Returns: The bounded sprite.
screenWrap(FlixelSprite, boolean, boolean, boolean, boolean)
Wraps the sprite when it leaves the game view (same default max as FlixelSpriteUtil.bound(...) when zeros).
Parameters:
| Name | Description |
|---|---|
sprite | The sprite to wrap. |
left | Whether to wrap the sprite when it leaves the left edge of the game view. |
right | Whether to wrap the sprite when it leaves the right edge of the game view. |
top | Whether to wrap the sprite when it leaves the top edge of the game view. |
bottom | Whether to wrap the sprite when it leaves the bottom edge of the game view. |
Returns: The wrapped sprite.
cameraBound(FlixelSprite, FlixelCamera, boolean, boolean, boolean, boolean)
Keeps the sprite inside the given camera world view (FlixelCamera.getViewLeft() etc.).
Parameters:
| Name | Description |
|---|---|
sprite | The sprite to bound. |
camera | The camera to bound the sprite to. |
left | Whether to bound the sprite when it leaves the left edge of the camera view. |
right | Whether to bound the sprite when it leaves the right edge of the camera view. |
top | Whether to bound the sprite when it leaves the top edge of the camera view. |
bottom | Whether to bound the sprite when it leaves the bottom edge of the camera view. |
Returns: The bounded sprite.
cameraWrap(FlixelSprite, FlixelCamera, boolean, boolean, boolean, boolean)
Wraps the sprite relative to the camera view edges.
Parameters:
| Name | Description |
|---|---|
sprite | The sprite to wrap. |
camera | The camera to wrap the sprite relative to. |
left | Whether to wrap the sprite when it leaves the left edge of the camera view. |
right | Whether to wrap the sprite when it leaves the right edge of the camera view. |
top | Whether to wrap the sprite when it leaves the top edge of the camera view. |
bottom | Whether to wrap the sprite when it leaves the bottom edge of the camera view. |
Returns: The wrapped sprite.
fill(FlixelSprite, Color)
Fills the active bitmap area with a solid color, similar to HaxeFlixel FlxSpriteUtil.fill.
When the sprite uses an owned pixmap-backed Texture (FlixelSprite.hasOwnedGraphic()), every pixel in the current TextureRegion (animation frame or static region) is overwritten via Texture.draw(...) without replacing the graphic.
Otherwise (shared atlas, unloaded graphic, or non-pixmap GPU texture) this falls back to FlixelSprite.makeGraphic(...) sized to the logical frame (FlixelFrame.originalWidth / FlixelFrame.originalHeight when set, else region size, else object size).
Parameters:
| Name | Description |
|---|---|
sprite | The sprite to fill. |
fillColor | The color to fill with (including alpha). |
Returns: sprite for chaining.
setBrightness(FlixelSprite, float)
Adjusts RGB toward white (brightness = 1) or black (brightness = -1), matching Adobe Animate style brightness as described for FlixelGDX FlixelSpriteUtil.setBrightness. Alpha is preserved.
Parameters:
| Name | Description |
|---|---|
sprite | The sprite to set the brightness of. |
brightness | Clamped to [-1, 1]. |
drawLine(Batch, Texture, float, float, float, float, float, Color)
Draws a line segment using a 1x1 texture and Batch. Does not allocate.
Parameters:
| Name | Description |
|---|---|
batch | The batch to draw the line on. |
whitePixel | The white pixel texture to use for the line. |
startX | The x position of the start of the line. |
startY | The y position of the start of the line. |
endX | The x position of the end of the line. |
endY | The y position of the end of the line. |
thickness | The thickness of the line. |
color | The color of the line. |
getMidpoint(FlixelSprite, Vector2)
Midpoint of the given sprite's hitbox in world space. Reuses out when non-null.
Parameters:
| Name | Description |
|---|---|
sprite | The sprite to get the midpoint of. |
out | The vector to store the midpoint in. |
Returns: The midpoint of the sprite.