diff --git a/src/main/java/ca/blarg/gdx/graphics/atlas/TextureAtlas.java b/src/main/java/ca/blarg/gdx/graphics/atlas/TextureAtlas.java index 1874c9f..fd8ce8c 100644 --- a/src/main/java/ca/blarg/gdx/graphics/atlas/TextureAtlas.java +++ b/src/main/java/ca/blarg/gdx/graphics/atlas/TextureAtlas.java @@ -8,13 +8,22 @@ import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.ObjectMap; public abstract class TextureAtlas { + public class Animation { + public String name; + public int destTileIndex; + public int start; + public int stop; + public float delay; + public boolean loop; + } + public static final float TEXCOORD_EDGE_BLEED_OFFSET = 0.02f; public final Texture texture; protected final float edgeCoordOffset; protected Array tiles = new Array(TextureRegion.class); - protected ObjectMap animations = new ObjectMap(); + protected ObjectMap animations = new ObjectMap(); public TextureAtlas(Texture texture, float edgeCoordOffset) { this.texture = texture; @@ -33,10 +42,24 @@ public abstract class TextureAtlas { return animations.size > 0; } - public ObjectMap.Entries getAnimations() { + public ObjectMap.Entries getAnimations() { return animations.entries(); } + public void addAnimation(String name, int destTileIndex, int start, int stop, float delay, boolean loop) { + if (animations.containsKey(name)) + throw new UnsupportedOperationException("Duplicate animation sequence name."); + + Animation animation = new Animation(); + animation.name = name; + animation.destTileIndex = destTileIndex; + animation.start = start; + animation.stop = stop; + animation.delay = delay; + animation.loop = loop; + animations.put(name, animation); + } + public static void scaleTexCoord(Vector2 texCoord, TextureRegion tile, Vector2 out) { out.x = scaleTexCoordU(texCoord.x, tile); out.y = scaleTexCoordV(texCoord.y, tile);