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-23 15:43:24 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2018-11-23 15:43:24 +0100
commite62c838c3da5cd091c86844d3e8649ba4c3fe5dd (patch)
treecfa8823479e5fdf7189077bfec675f747501ec2a /core/src/ch/asynk/gdx/boardgame/FramedSprite.java
parent5591bf3f826eff842e019bc82db5ae53aacba416 (diff)
downloadgdx-boardgame-e62c838c3da5cd091c86844d3e8649ba4c3fe5dd.zip
gdx-boardgame-e62c838c3da5cd091c86844d3e8649ba4c3fe5dd.tar.gz
FramedSprite : add x,y,a .. vars
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);
}
}