Guest User

Untitled

a guest
Dec 17th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. public class Animation {
  2. Array<TextureRegion> frames;
  3. float maxFrameTime;
  4. float currentFrameTime;
  5. int frameCount;
  6. int frame;
  7. Boolean playedOnce;
  8.  
  9. public void dispose(){
  10. frames=null;
  11. }
  12.  
  13. public Animation(TextureRegion region, int frameCount, float cycleTime){
  14. playedOnce=false;
  15. frames = new Array<TextureRegion>();
  16. TextureRegion temp;
  17. int frameWidth = region.getRegionWidth() / frameCount;
  18. for(int i = 0; i < frameCount; i++){
  19. temp = new TextureRegion(region, i * frameWidth, 0, frameWidth, region.getRegionHeight());
  20. frames.add(temp);
  21. }
  22. this.frameCount = frameCount;
  23. this.maxFrameTime = cycleTime / frameCount;
  24. frame = 0;
  25. }
  26.  
  27. public void update(float dt){
  28. currentFrameTime += dt;
  29. if(currentFrameTime > maxFrameTime){
  30. frame++;
  31. currentFrameTime = 0;
  32. if(frame >= frameCount-1){
  33. playedOnce=true;
  34. }
  35. if(frame >= frameCount){
  36. frame = 0;
  37. }
  38. }
  39. }
  40.  
  41. public Boolean isPlayedOnce(){
  42. return playedOnce;
  43. }
  44.  
  45. public void flip(){
  46. for(TextureRegion region : frames)
  47. region.flip(true, false);
  48. }
  49.  
  50. public TextureRegion getFrame(){
  51. return frames.get(frame);
  52. }
Add Comment
Please, Sign In to add comment