Tiny 2D-animation-sprite composer for placing animation loops and making them interactive
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. Marker[] marker;
  2. class Marker {
  3. PImage[] idleImages;
  4. PImage[] actionImages;
  5. String idlePath;
  6. String actionPath;
  7. int id;
  8. int frameIdle;
  9. int frameAction;
  10. int idleImageCount, actionImageCount;
  11. float canvasPosX, canvasPosY;
  12. float canvasImgW, canvasImgH;
  13. boolean dead;
  14. boolean loadActionRoutine;
  15. boolean hasAction;
  16. boolean waitForPlay;
  17. boolean playAction;
  18. boolean locked;
  19. boolean drag;
  20. boolean hover() {
  21. if (viewX > canvasPosX && viewX < canvasPosX + canvasImgW && viewY > canvasPosY && viewY < canvasPosY+ canvasImgW) {
  22. return true;
  23. } else {
  24. return false;
  25. }
  26. }
  27. Marker(int idtemp, File[] i, int x, int y, String fp) { //casual idle import via drag'n'drop, no action animation
  28. id = idtemp;
  29. idlePath = fp + "/idle";
  30. loadSequence(i);
  31. hasAction = false;
  32. canvasPosX = viewyfyX(x) - canvasImgW/2;
  33. canvasPosY = viewyfyY(y) - canvasImgH/2;
  34. }
  35. Marker(int idtemp, File[] i, File[] a, int x, int y, String fp) { //casual import via drag'n'drop with action animation
  36. id = idtemp;
  37. idlePath = fp + "/idle";
  38. actionPath = fp + "/action";
  39. loadSequence(i);
  40. loadSequence(a);
  41. hasAction = true;
  42. canvasPosX = viewyfyX(x) - canvasImgW/2;
  43. canvasPosY = viewyfyY(y) - canvasImgH/2;
  44. }
  45. Marker(int idtemp, String i, String a, int x, int y, float cw, float ch) { //import from savefile
  46. id = idtemp;
  47. idlePath = i;
  48. actionPath = a;
  49. File idleDir = new File(i);
  50. File[] idleFiles = idleDir.listFiles();
  51. loadSequence(idleFiles);
  52. if (!a.equals("null")) {
  53. File actionDir = new File(a);
  54. File[] actionFiles = actionDir.listFiles();
  55. loadSequence(actionFiles);
  56. hasAction = true;
  57. } else {
  58. hasAction = false;
  59. }
  60. canvasPosX = x;
  61. canvasPosY = y;
  62. canvasImgW = cw;
  63. canvasImgH = ch;
  64. }
  65. void loadSequence(File[] filestemp) { //load images
  66. File files[] = filestemp;
  67. String filePaths[] = new String[files.length];
  68. int imageCount = 0;
  69. for (int i = 0; i < files.length; i++) {
  70. filePaths[i] = files[i].getAbsolutePath();
  71. if (isImage(filePaths[i])) {
  72. imageCount++;
  73. }
  74. }
  75. filePaths = sort(filePaths);
  76. if (imageCount > 0) {
  77. if (!loadActionRoutine) idleImages = new PImage[imageCount];
  78. else actionImages = new PImage[imageCount];
  79. imageCount = 0;
  80. println("Loading animation...");
  81. for (int i = 0; i < files.length; i++) {
  82. if (isImage(files[i].getAbsolutePath())) {
  83. if (!loadActionRoutine) idleImages[imageCount] = loadImage(filePaths[i]);
  84. else actionImages[imageCount] = loadImage(filePaths[i]);
  85. println("Loading image number..." + imageCount);
  86. imageCount++;
  87. }
  88. }
  89. if (!loadActionRoutine) {
  90. idleImageCount = imageCount;
  91. canvasImgW = idleImages[0].width; //assuming all images have the same size
  92. canvasImgH = idleImages[0].height;
  93. loadActionRoutine = true; //CAREFUL!! This is specifically designed for maximum 2 imports.
  94. } else {
  95. actionImageCount = imageCount;
  96. loadActionRoutine = false;
  97. }
  98. } else {
  99. println("This folder contains no PNGs and / or no GIFs.");
  100. }
  101. }
  102. void rightClicked() {
  103. if (!locked) {
  104. draggingAsset = true;
  105. drag = true;
  106. clickedMarkerID = id;
  107. }
  108. }
  109. void leftClicked() {
  110. if (hasAction && !waitForPlay && !playAction) {
  111. waitForPlay = true;
  112. }
  113. }
  114. void display() {
  115. if (!dead) {
  116. frameIdle = (frameIdle+1) % idleImageCount;
  117. if (waitForPlay) {
  118. if (frameIdle >= idleImageCount - 1) {
  119. waitForPlay = false;
  120. playAction = true;
  121. }
  122. }
  123. if (playAction) {
  124. frameAction = (frameAction+1) % actionImageCount;
  125. renderer.image(actionImages[frameAction], canvasPosX, canvasPosY, canvasImgW, canvasImgH);
  126. if (frameAction >= actionImageCount - 3) {
  127. playAction = false;
  128. frameIdle = 0;
  129. }
  130. } else {
  131. renderer.image(idleImages[frameIdle], canvasPosX, canvasPosY, canvasImgW, canvasImgH);
  132. }
  133. }
  134. }
  135. void saveToFile() throws IOException { //open the IO stream outside...
  136. //output.write("\"id\": " + str(id) + ",\n");
  137. //output.write("\"idlePath\": \"/" + idlePath + "\",\n");
  138. //output.write("\"actionPath\": \"" + actionPath + "\",\n");
  139. //output.write("\"x-position\": " + canvasPosX +",\n");
  140. //output.write("\"y-position\": " + canvasPosY + ",\n");
  141. //output.write("\"width\": " + canvasImgW + ",\n");
  142. //output.write("\"height\": " + canvasImgH);
  143. output.write(str(id) + "\n");
  144. output.write(idlePath + "\n");
  145. output.write(actionPath + "\n");
  146. output.write(canvasPosX +"\n");
  147. output.write(canvasPosY + "\n");
  148. output.write(canvasImgW + "\n");
  149. output.write(canvasImgH + "\n");
  150. }
  151. void kill() {
  152. dead = true;
  153. drag = false;
  154. Marker temp = marker[activeMarkers-1];
  155. marker[activeMarkers-1] = marker[id];
  156. marker[id] = temp;
  157. activeMarkers--;
  158. draggingAsset = false;
  159. }
  160. }