From 42f5238c3341437e9d55f14715033b03aad60fc8 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Mon, 29 Aug 2022 00:40:49 +0600 Subject: важное переименовывание папок MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ilotterytea/maxoning/ui/AnimatedImage.java | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 core/src/com/ilotterytea/maxoning/ui/AnimatedImage.java (limited to 'core/src/com/ilotterytea/maxoning/ui') diff --git a/core/src/com/ilotterytea/maxoning/ui/AnimatedImage.java b/core/src/com/ilotterytea/maxoning/ui/AnimatedImage.java new file mode 100644 index 0000000..521059e --- /dev/null +++ b/core/src/com/ilotterytea/maxoning/ui/AnimatedImage.java @@ -0,0 +1,38 @@ +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.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(); + } + } + } +} -- cgit v1.2.3