Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1.  
  2. public class animationData{
  3. private String name;
  4. private int id;
  5.  
  6. animationData(String n, int i){
  7. name = n;
  8. id = i;
  9. }
  10.  
  11. public String getName(){
  12. return name;
  13. }
  14. public int getId(){
  15. return id;
  16. }
  17. }
  18.  
  19.  
  20. public class AnimationModule extends ApplicationAdapter {
  21. Animation animation;
  22. TextureAtlas cry;
  23. TextureAtlas clap;
  24. TextureAtlas think;
  25. TextureAtlas atlas;
  26. TextureRegion[] frames;
  27. float speed;
  28. String prefix = "Dracek";
  29. String regionName;
  30.  
  31. AnimationModule()
  32. {
  33. cry = new TextureAtlas(Gdx.files.internal("Spritesheets/DracekCry.atlas"));;
  34. clap = new TextureAtlas(Gdx.files.internal("Spritesheets/DracekClap.atlas"));;
  35. think = new TextureAtlas(Gdx.files.internal("Spritesheets/DracekThink.atlas"));;
  36. frames = new TextureRegion[20];
  37. }
  38.  
  39. private void setAnimationSpeeds(float s) {
  40. speed = s;
  41. }
  42.  
  43.  
  44. private void setFrames(int s, int r) {
  45.  
  46.  
  47. for (int i = 1; i <= s; i++) {
  48. regionName = prefix + String.valueOf(i);
  49. frames[i - 1] = atlas.findRegion(regionName);
  50. }
  51. for (int i = s + 1; i <= 20; i++) {
  52. regionName = prefix + String.valueOf((s + 1) + (i % r));
  53. frames[i - 1] = atlas.findRegion(regionName);
  54. }
  55. }
  56.  
  57. public Animation createAnimation(int n) {
  58.  
  59. switch (n) {
  60. case 1:
  61. atlas = cry;
  62. setAnimationSpeeds(1f / 15f);
  63. setFrames(6, 2);
  64. break;
  65. case 2:
  66. atlas = clap;
  67. setAnimationSpeeds(1f / 30f);
  68. setFrames(6, 2);
  69. break;
  70. case 3:
  71. atlas = think;
  72. setAnimationSpeeds(1f / 10f);
  73. setFrames(3, 2);
  74. break;
  75. default:
  76. break;
  77. }
  78.  
  79. animation = new Animation(speed, frames);
  80. return animation;
  81. }
  82.  
  83. public ArrayList getAnimationList() {
  84.  
  85. ArrayList outputData = new ArrayList<animationData>();
  86. outputData.add(new animationData("None", -1));
  87. outputData.add(new animationData("Cry", 1));
  88. outputData.add(new animationData("Clap", 2));
  89. outputData.add(new animationData("Think", 3));
  90.  
  91. return outputData;
  92. }
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement