You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

76 lines
1.2 KiB

  1. define([
  2. 'js/rendering/renderer'
  3. ], function(
  4. renderer
  5. ) {
  6. return {
  7. type: 'animation',
  8. frames: 4,
  9. frameDelay: 4,
  10. sheet: 'attacks',
  11. row: null,
  12. col: null,
  13. loop: 1,
  14. loopCounter: 0,
  15. frame: 0,
  16. frameDelayCd: 0,
  17. oldTexture: null,
  18. init: function(blueprint) {
  19. if (!this.obj.sprite)
  20. return true;
  21. this.oldTexture = this.obj.sprite.texture;
  22. this.frame = 0;
  23. this.frameDelayCd = 0;
  24. for (var p in this.template) {
  25. this[p] = this.template[p];
  26. }
  27. this.frameDelayCd = this.frameDelay;
  28. this.setSprite();
  29. },
  30. setSprite: function() {
  31. renderer.setSprite({
  32. sprite: this.obj.sprite,
  33. cell: (this.row * 8) + this.col + this.frame,
  34. sheetName: this.sheet
  35. });
  36. },
  37. update: function() {
  38. if (this.frameDelayCd > 0)
  39. this.frameDelayCd--;
  40. else {
  41. this.frameDelayCd = this.frameDelay;
  42. this.frame++;
  43. if (this.frame == this.frames) {
  44. this.loopCounter++;
  45. if (this.loopCounter == this.loop) {
  46. this.destroyed = true;
  47. return;
  48. }
  49. else
  50. this.frame = 0;
  51. }
  52. }
  53. this.setSprite();
  54. },
  55. destroy: function() {
  56. this.obj.sprite.texture = this.oldTexture;
  57. }
  58. };
  59. });