diff options
| author | ilotterytea <iltsu@alright.party> | 2022-08-31 02:59:50 +0600 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2022-08-31 02:59:50 +0600 |
| commit | da368edfcba5a0164b923c9f9a7452af2802b315 (patch) | |
| tree | 1fc690e26bba65d81fa4e70cae6cb92ad6b30d79 /core | |
| parent | 9c63c76742e115082b39b1fe53167a27ca2f48f4 (diff) | |
stop animation boolean and get drawable
Diffstat (limited to 'core')
| -rw-r--r-- | core/src/com/ilotterytea/maxoning/ui/AnimatedImage.java | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/core/src/com/ilotterytea/maxoning/ui/AnimatedImage.java b/core/src/com/ilotterytea/maxoning/ui/AnimatedImage.java index 521059e..ebfd89a 100644 --- a/core/src/com/ilotterytea/maxoning/ui/AnimatedImage.java +++ b/core/src/com/ilotterytea/maxoning/ui/AnimatedImage.java @@ -1,34 +1,56 @@ package com.ilotterytea.maxoning.ui; -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.Drawable; import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; +import com.badlogic.gdx.utils.Disposable; -public class AnimatedImage extends Image { - private float stateTime = 0; +public class AnimatedImage extends Image implements Disposable { private final TextureRegion[] regions; private int index = 0; + private boolean stopAnim = false; + public AnimatedImage(TextureRegion[] regions) { super(regions[0]); this.regions = regions; } @Override public void act(float delta) { - if (index > regions.length - 1) { - index = 0; + if (!stopAnim) { + if (index > regions.length - 1) { + index = 0; + } + if (regions[index + 1] == null) { + index = 0; + } + super.setDrawable(new TextureRegionDrawable(regions[index])); + index++; } - if (regions[index + 1] == null) { + super.act(delta); + } + + public TextureRegion getFrame(int index) { return regions[index]; } + public int getIndex() { return index; } + public Drawable getDrawable() { return super.getDrawable(); } + + public void nextFrame() { + index++; + + if (index > regions.length - 1 || regions[index] == null) { index = 0; } - super.setDrawable(new TextureRegionDrawable(regions[index])); - index++; - super.act(delta); + super.setDrawable(new TextureRegionDrawable(regions[index])); } - public void dispose() { + public void disableAnim() { stopAnim = true; } + public void enableAnim() { stopAnim = false; } + + public boolean isAnimationStopped() { return stopAnim; } + + @Override public void dispose() { for (TextureRegion reg : regions) { if (reg != null) { reg.getTexture().dispose(); |
