From da368edfcba5a0164b923c9f9a7452af2802b315 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Wed, 31 Aug 2022 02:59:50 +0600 Subject: stop animation boolean and get drawable --- .../com/ilotterytea/maxoning/ui/AnimatedImage.java | 42 ++++++++++++++++------ 1 file changed, 32 insertions(+), 10 deletions(-) (limited to 'core/src/com/ilotterytea') 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(); -- cgit v1.2.3