diff options
| author | ilotterytea <iltsu@alright.party> | 2024-10-07 02:35:36 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2024-10-07 02:35:36 +0500 |
| commit | 2451b7d78a1f0bd9df1d01f254c30a14b731688a (patch) | |
| tree | 3d36f3c4ff1788dc7c1f43ee205e38285fc54544 /core/src/kz/ilotterytea/maxon/ui | |
| parent | 3de9d004e99851f38f8700839fa2f7aa6f1c0172 (diff) | |
upd: splitToTextureRegions returns now ArrayList because default arrays fucking suck
Diffstat (limited to 'core/src/kz/ilotterytea/maxon/ui')
| -rw-r--r-- | core/src/kz/ilotterytea/maxon/ui/AnimatedImage.java | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/core/src/kz/ilotterytea/maxon/ui/AnimatedImage.java b/core/src/kz/ilotterytea/maxon/ui/AnimatedImage.java index e6278c5..d1f5b90 100644 --- a/core/src/kz/ilotterytea/maxon/ui/AnimatedImage.java +++ b/core/src/kz/ilotterytea/maxon/ui/AnimatedImage.java @@ -6,37 +6,39 @@ import com.badlogic.gdx.scenes.scene2d.utils.Drawable; import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; import com.badlogic.gdx.utils.Disposable; +import java.util.ArrayList; + public class AnimatedImage extends Image implements Disposable { - private final TextureRegion[] regions; + private final ArrayList<TextureRegion> regions; private final int fps; private int index = 0, seconds = 0; private boolean stopAnim = false; - public AnimatedImage(TextureRegion[] regions) { - super(regions[0]); + public AnimatedImage(ArrayList<TextureRegion> regions) { + super(regions.get(0)); this.regions = regions; this.fps = 0; } - public AnimatedImage(TextureRegion[] regions, int fps) { - super(regions[0]); + public AnimatedImage(ArrayList<TextureRegion> regions, int fps) { + super(regions.get(0)); this.regions = regions; this.fps = fps; } @Override public void act(float delta) { if (!stopAnim && seconds >= fps) { - if (index > regions.length - 1) { + if (index > regions.size() - 1) { index = 0; } try { - if (regions[index + 1] == null) { + if (regions.get(index + 1) == null) { index = 0; } - } catch (ArrayIndexOutOfBoundsException ignored) {} + } catch (IndexOutOfBoundsException ignored) {} - super.setDrawable(new TextureRegionDrawable(regions[index])); + super.setDrawable(new TextureRegionDrawable(regions.get(index))); index++; seconds = 0; } @@ -45,18 +47,18 @@ public class AnimatedImage extends Image implements Disposable { super.act(delta); } - public TextureRegion getFrame(int index) { return regions[index]; } + public TextureRegion getFrame(int index) { return regions.get(index); } public int getIndex() { return index; } public Drawable getDrawable() { return super.getDrawable(); } public void nextFrame() { index++; - if (index > regions.length - 1 || regions[index] == null) { + if (index > regions.size() - 1 || regions.get(index) == null) { index = 0; } - super.setDrawable(new TextureRegionDrawable(regions[index])); + super.setDrawable(new TextureRegionDrawable(regions.get(index))); } public void disableAnim() { stopAnim = true; } |
