From 8833419a56c090fc357ee483556428196d26ed67 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sun, 9 Jun 2024 23:25:37 +0500 Subject: feat: fps for animated images --- core/src/kz/ilotterytea/maxon/pets/Pet.java | 2 +- core/src/kz/ilotterytea/maxon/ui/AnimatedImage.java | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'core') diff --git a/core/src/kz/ilotterytea/maxon/pets/Pet.java b/core/src/kz/ilotterytea/maxon/pets/Pet.java index c39e77e..4b4cb00 100644 --- a/core/src/kz/ilotterytea/maxon/pets/Pet.java +++ b/core/src/kz/ilotterytea/maxon/pets/Pet.java @@ -44,7 +44,7 @@ public class Pet { regions = new TextureRegion[]{new TextureRegion(MaxonConstants.MISSING_TEXTURE)}; } - AnimatedImage icon = new AnimatedImage(regions); + AnimatedImage icon = new AnimatedImage(regions, 5); String name = game.locale.TranslatableText("pet." + id + ".name"); if (name == null) { diff --git a/core/src/kz/ilotterytea/maxon/ui/AnimatedImage.java b/core/src/kz/ilotterytea/maxon/ui/AnimatedImage.java index 19ec0dc..e6278c5 100644 --- a/core/src/kz/ilotterytea/maxon/ui/AnimatedImage.java +++ b/core/src/kz/ilotterytea/maxon/ui/AnimatedImage.java @@ -8,17 +8,25 @@ import com.badlogic.gdx.utils.Disposable; public class AnimatedImage extends Image implements Disposable { private final TextureRegion[] regions; - private int index = 0; + private final int fps; + private int index = 0, seconds = 0; private boolean stopAnim = false; public AnimatedImage(TextureRegion[] regions) { super(regions[0]); this.regions = regions; + this.fps = 0; + } + + public AnimatedImage(TextureRegion[] regions, int fps) { + super(regions[0]); + this.regions = regions; + this.fps = fps; } @Override public void act(float delta) { - if (!stopAnim) { + if (!stopAnim && seconds >= fps) { if (index > regions.length - 1) { index = 0; } @@ -30,7 +38,10 @@ public class AnimatedImage extends Image implements Disposable { super.setDrawable(new TextureRegionDrawable(regions[index])); index++; + seconds = 0; } + + seconds++; super.act(delta); } -- cgit v1.2.3