Advertisement
Jeyjey0

Animation Class Java

Sep 15th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. package Graphics;
  2.  
  3. import java.awt.image.BufferedImage;
  4.  
  5. public class Animation {
  6.  
  7. private int speed,index;
  8. private long lastTime, timer;
  9. private BufferedImage[] frames;
  10. protected int count = 0;
  11. public Animation(int speed, BufferedImage[] frames){
  12. this.speed = speed;
  13. this.frames = frames;
  14. index = 0;
  15. lastTime = System.currentTimeMillis();
  16. }
  17.  
  18. public void tick(){
  19. timer += System.currentTimeMillis() - lastTime;
  20. lastTime = System.currentTimeMillis();
  21. if(frames != null)
  22. if(timer > speed){
  23. index++;
  24. timer = 0;
  25. if(index >= frames.length){
  26. index = 0;
  27. count += 1;
  28. resetAni =true;
  29. }
  30. }
  31. }
  32.  
  33. public BufferedImage getCurrentFrame(){
  34. return frames[index];
  35. }
  36. public boolean resetAni = false;
  37. public int getCount(){
  38. return count;
  39. }
  40.  
  41. public void setSpeed(int s){
  42. this.speed=s;
  43. }
  44. public void setCount(int i) {
  45. count = i;
  46.  
  47. }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement