summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2024-06-09 23:25:37 +0500
committerilotterytea <iltsu@alright.party>2024-06-09 23:25:37 +0500
commit8833419a56c090fc357ee483556428196d26ed67 (patch)
treeed7b412b8e10262fd203d3321770a448f909f602
parentabb6614122bf9eaee9b3b1aa3ac3083c74c40e48 (diff)
feat: fps for animated images
-rw-r--r--core/src/kz/ilotterytea/maxon/pets/Pet.java2
-rw-r--r--core/src/kz/ilotterytea/maxon/ui/AnimatedImage.java15
2 files changed, 14 insertions, 3 deletions
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);
}