summaryrefslogtreecommitdiff
path: root/core/src/com/ilotterytea/maxoning/anim
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/com/ilotterytea/maxoning/anim')
-rw-r--r--core/src/com/ilotterytea/maxoning/anim/AnimatedImage.java38
-rw-r--r--core/src/com/ilotterytea/maxoning/anim/SpriteUtils.java34
2 files changed, 72 insertions, 0 deletions
diff --git a/core/src/com/ilotterytea/maxoning/anim/AnimatedImage.java b/core/src/com/ilotterytea/maxoning/anim/AnimatedImage.java
new file mode 100644
index 0000000..8da1c19
--- /dev/null
+++ b/core/src/com/ilotterytea/maxoning/anim/AnimatedImage.java
@@ -0,0 +1,38 @@
+package com.ilotterytea.maxoning.anim;
+
+import com.badlogic.gdx.graphics.g2d.Animation;
+import com.badlogic.gdx.graphics.g2d.TextureRegion;
+import com.badlogic.gdx.scenes.scene2d.ui.Image;
+import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
+
+public class AnimatedImage extends Image {
+ private float stateTime = 0;
+ private final TextureRegion[] regions;
+ private int index = 0;
+
+ public AnimatedImage(TextureRegion[] regions) {
+ super(regions[0]);
+ this.regions = regions;
+ }
+
+ @Override public void act(float delta) {
+ if (index > regions.length - 1) {
+ index = 0;
+ }
+ if (regions[index + 1] == null) {
+ index = 0;
+ }
+ super.setDrawable(new TextureRegionDrawable(regions[index]));
+ index++;
+ super.act(delta);
+
+ }
+
+ public void dispose() {
+ for (TextureRegion reg : regions) {
+ if (reg != null) {
+ reg.getTexture().dispose();
+ }
+ }
+ }
+}
diff --git a/core/src/com/ilotterytea/maxoning/anim/SpriteUtils.java b/core/src/com/ilotterytea/maxoning/anim/SpriteUtils.java
new file mode 100644
index 0000000..63c4f0b
--- /dev/null
+++ b/core/src/com/ilotterytea/maxoning/anim/SpriteUtils.java
@@ -0,0 +1,34 @@
+package com.ilotterytea.maxoning.anim;
+
+import com.badlogic.gdx.graphics.Texture;
+import com.badlogic.gdx.graphics.g2d.TextureRegion;
+
+import java.util.Arrays;
+
+public class SpriteUtils {
+ public static TextureRegion[] splitToTextureRegions(
+ Texture texture,
+ int tileWidth,
+ int tileHeight,
+ int columns,
+ int rows
+ ) {
+ TextureRegion[][] tmp = TextureRegion.split(texture, tileWidth, tileHeight);
+ TextureRegion[] frames = new TextureRegion[(texture.getWidth() / columns) + (texture.getHeight() / rows)];
+
+ int index = 0;
+
+ for (TextureRegion[] regArray : tmp) {
+ for (TextureRegion reg : regArray) {
+ if (reg != null) {
+ frames[index++] = reg;
+ }
+ }
+ }
+
+ System.out.println(Arrays.deepToString(tmp));
+ System.out.println(frames.length);
+
+ return frames;
+ }
+}