如何使自定义动画播放一次

时间:2016-06-15 12:12:43

标签: java android animation android-studio

这是我用来在SurfaceView中绘制对象的动画类:

import android.graphics.Bitmap;

public class Animation {
private Bitmap[] frames;
private int currentFrame;
private long startTime;
private long delay;
private boolean playedOnce;

public void setFrames(Bitmap[] frames)
{
    this.frames = frames;
    currentFrame = 0;
    startTime = System.nanoTime();
}
public void setDelay(long d){delay = d;}
public void setFrame(int i){currentFrame= i;}

public void update()
{
    long elapsed = (System.nanoTime()-startTime)/1000000;

    if(elapsed>delay)
    {
        currentFrame++;
        startTime = System.nanoTime();
    }
    if(currentFrame == frames.length){
        currentFrame = 0;
        playedOnce = true;
    }
}
public Bitmap getImage(){
    return frames[currentFrame];
}
public int getFrame(){return currentFrame;}
public boolean playedOnce(){
    return playedOnce;
}

}
但是!playedOnce方法不起作用!
动画保持循环..
我错过了什么吗?怎么解决这个问题?

0 个答案:

没有答案