Package org.xjge.graphics
Class SpriteAnimation
java.lang.Object
org.xjge.graphics.SpriteAnimation
public class SpriteAnimation
extends java.lang.Object
Represents a 2D sprite animation that iterates over a series of sub-images
from a texture atlas in sequence to create the illusion
of movement.
- Since:
- 2.0.0
-
Field Summary
-
Constructor Summary
Constructors Constructor Description SpriteAnimation(java.util.ArrayList<org.joml.Vector2i> frames, int speed)
Creates a new 2D animation using the frames provided.SpriteAnimation(org.joml.Vector2i frame)
Creates a new single-frame animation- a non-animation if you will. -
Method Summary
Modifier and Type Method Description void
update(org.joml.Vector2f texCoords, Atlas atlas, boolean sync)
Overloaded variant of theupdate()
method which stores the texture coordinates in the provided vector object.void
update(Atlas atlas, boolean sync)
Steps the animation forward changing the texture coordinates of the sprite sheet and subsequently the sub-image rendered.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
currFrame
public int currFrame -
speed
public int speed -
frames
public java.util.ArrayList<org.joml.Vector2i> frames
-
-
Constructor Details
-
SpriteAnimation
public SpriteAnimation(org.joml.Vector2i frame)Creates a new single-frame animation- a non-animation if you will.- Parameters:
frame
- the frame to display indefinitely until the animation is changed
-
SpriteAnimation
public SpriteAnimation(java.util.ArrayList<org.joml.Vector2i> frames, int speed)Creates a new 2D animation using the frames provided.- Parameters:
frames
- the frames that comprise the animation in sequencespeed
- the speed of the animation in game ticks
-
-
Method Details
-
update
Steps the animation forward changing the texture coordinates of the sprite sheet and subsequently the sub-image rendered.- Parameters:
atlas
- the texture atlas (or sprite sheet) to use for this animationsync
- if true, the animation wont use a stopwatch as its timing mechanism
-
update
Overloaded variant of theupdate()
method which stores the texture coordinates in the provided vector object. This is useful anytime you want to reuse the data from a texture atlas without altering its owntexCoords
field.- Parameters:
texCoords
- the vector object that can be passed to a shader programatlas
- the texture atlas (or sprite sheet) to use for this animationsync
- if true, the animation wont use a stopwatch as its timing mechanism
-