summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/gdx/boardgame/FramedSprite.java
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2018-11-14 00:29:49 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2018-11-14 00:29:49 +0100
commit53d9569112cc7a83a39c1d02c7afed26ee4e74e0 (patch)
treec417a038d37d55db1fb492bfd703d8045efcbf05 /core/src/ch/asynk/gdx/boardgame/FramedSprite.java
parent0b2d5739d8f620e06e9ee3aa5180f4f63559c20e (diff)
downloadgdx-boardgame-53d9569112cc7a83a39c1d02c7afed26ee4e74e0.zip
gdx-boardgame-53d9569112cc7a83a39c1d02c7afed26ee4e74e0.tar.gz
add FramedSprite
Diffstat (limited to 'core/src/ch/asynk/gdx/boardgame/FramedSprite.java')
-rw-r--r--core/src/ch/asynk/gdx/boardgame/FramedSprite.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/FramedSprite.java b/core/src/ch/asynk/gdx/boardgame/FramedSprite.java
new file mode 100644
index 0000000..027efb6
--- /dev/null
+++ b/core/src/ch/asynk/gdx/boardgame/FramedSprite.java
@@ -0,0 +1,37 @@
+package ch.asynk.gdx.boardgame;
+
+import com.badlogic.gdx.utils.Disposable;
+import com.badlogic.gdx.graphics.Texture;
+import com.badlogic.gdx.graphics.g2d.TextureRegion;
+
+public class FramedSprite implements Disposable
+{
+ public Texture texture;
+ public TextureRegion[] frames;
+ public final int width;
+ public final int height;
+ public final int cols;
+ public final int rows;
+
+ public FramedSprite(Texture texture, int cols, int rows)
+ {
+ this.cols = cols;
+ this.rows = rows;
+ this.width = (texture.getWidth() / cols);
+ this.height = (texture.getHeight() / rows);
+ this.texture = texture;
+ TextureRegion[][] tmp = TextureRegion.split(texture, width, height);
+ frames = new TextureRegion[cols * rows];
+ int idx = 0;
+ for (int i = 0; i < rows; i++) {
+ for (int j = 0; j < cols; j++) {
+ frames[idx++] = tmp[i][j];
+ }
+ }
+ }
+
+ @Override public void dispose()
+ {
+ texture.dispose();
+ }
+}