I am having some trouble getting my isAnimationFinished()
finished to work in a program I am working on. Currently, it seems to just always go into this method. Another issue with the animation is that it almost instantly goes through all the sprites where I would like to prolong each frame for about .25 seconds or so. My relevant code is below, any other questions or help would be appreciated!
Render Call:
public void render(float delta)
runTime += delta;
world.update(delta);
renderer.render(delta, runTime);
Animation Creation:
TextureRegion[] waterGraphics = { water1, water2, water3 };
waterAnimation = new Animation(0.25f, waterGraphics);
waterAnimation.setPlayMode(Animation.PlayMode.NORMAL);
Animation Draw:
if(!waterAnimation.isAnimationFinished(runTime)) {
//System.out.println("1");
batcher.draw(waterAnimation.getKeyFrame(runTime), penguin.getX()+30,
penguin.getY(), penguin.getWidth() / 2.0f,
penguin.getHeight() / 2.0f, penguin.getWidth()*5, penguin.getHeight()*5,
1, 1, penguin.getRotation()); // Don't leave at *5.....
simpleCounter++;
}
Thanks
you can use this animation class what i am using for my project.To check for finish you can check if last frame is running by getCurrentFrame()
method.
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
public class Animation {
private Sprite[] frames;
private float time;
private float delay;
private int currentframe;
private int timesplayed;
public Animation(){}
public Animation(TextureRegion[] frames){
this(frames, 1/12);
}
public Animation(TextureRegion[] frames,float delay){
this.setFrames(frames, delay);
}
public Animation(Sprite []a,float delay){
this.frames=a;
this.delay=delay;
time=0;
currentframe=0;
timesplayed=0;
}
public void setFrames(TextureRegion[] frames,float delay){
this.frames=new Sprite[frames.length];
for(int i=0;i<frames.length;i++){
this.frames[i]=new Sprite(frames[i]);
this.frames[i].getTexture().setFilter(TextureFilter.Linear,TextureFilter.Linear);
}
this.delay=delay;
time=0;
currentframe=0;
timesplayed=0;
}
public void update(float dt){
if(delay<=0)return;
time+=dt;
while(time >= delay)step();
}
private void step() {
time-=delay;
currentframe++;
if(currentframe==frames.length)
currentframe=0;
timesplayed++;
}
public Sprite getFrames() {
return frames[currentframe];
}
public float getTime() {
return time;
}
public void setTime(float time) {
this.time = time;
}
public float getDelay() {
return delay;
}
public void setDelay(float delay) {
this.delay = delay;
}
public int getCurrentframe() {
return currentframe;
}
public void setCurrentframe(int currentframe) {
this.currentframe = currentframe;
}
public int getTimesplayed() {
return timesplayed;
}
public void setTimesplayed(int timesplayed) {
this.timesplayed = timesplayed;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.