summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/gdx/boardgame/FramedSprite.java
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch/asynk/gdx/boardgame/FramedSprite.java')
-rw-r--r--core/src/ch/asynk/gdx/boardgame/FramedSprite.java60
1 files changed, 41 insertions, 19 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/FramedSprite.java b/core/src/ch/asynk/gdx/boardgame/FramedSprite.java
index 33ca5ce..33a6eb2 100644
--- a/core/src/ch/asynk/gdx/boardgame/FramedSprite.java
+++ b/core/src/ch/asynk/gdx/boardgame/FramedSprite.java
@@ -1,31 +1,53 @@
package ch.asynk.gdx.boardgame;
import com.badlogic.gdx.graphics.Texture;
+import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
-public class FramedSprite
+public class FramedSprite implements Drawable
{
- public Texture texture;
- public TextureRegion[] frames;
- public final int width;
- public final int height;
- public final int cols;
+ private TextureRegion[][] frames;
+ private TextureRegion frame;
public final int rows;
+ public final int cols;
+ public float x;
+ public float y;
+ public float a;
- public FramedSprite(Texture texture, int cols, int rows)
+ public FramedSprite(Texture texture, int rows, int cols)
{
- this.cols = cols;
+ this.frames = TextureRegion.split(texture, (texture.getWidth() / cols), (texture.getHeight() / rows));
+ this.frame = frames[0][0];
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];
- }
- }
+ this.cols = cols;
+ this.x = 0;
+ this.y = 0;
+ this.a = 0;
+ }
+
+ public FramedSprite(FramedSprite other)
+ {
+ this.frames = other.frames;
+ this.frame = other.frame;
+ this.rows = other.rows;
+ this.cols = other.cols;
+ this.x = other.x;
+ this.y = other.y;
+ this.a = other.a;
+ }
+
+ public void setFrame(int row, int col)
+ {
+ this.frame = frames[row][col];
+ }
+
+ public TextureRegion getFrame()
+ {
+ return frame;
+ }
+
+ @Override public void draw(Batch batch)
+ {
+ batch.draw(frame, x, y, 0, 0, frame.getRegionWidth(), frame.getRegionHeight(), 1f, 1f, a);
}
}