Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Graphics;
- import java.awt.image.BufferedImage;
- public class Animation {
- private int speed,index;
- private long lastTime, timer;
- private BufferedImage[] frames;
- protected int count = 0;
- public Animation(int speed, BufferedImage[] frames){
- this.speed = speed;
- this.frames = frames;
- index = 0;
- lastTime = System.currentTimeMillis();
- }
- public void tick(){
- timer += System.currentTimeMillis() - lastTime;
- lastTime = System.currentTimeMillis();
- if(frames != null)
- if(timer > speed){
- index++;
- timer = 0;
- if(index >= frames.length){
- index = 0;
- count += 1;
- resetAni =true;
- }
- }
- }
- public BufferedImage getCurrentFrame(){
- return frames[index];
- }
- public boolean resetAni = false;
- public int getCount(){
- return count;
- }
- public void setSpeed(int s){
- this.speed=s;
- }
- public void setCount(int i) {
- count = i;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement