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.
 
 
 

75 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 (let p in this.template)
  25. this[p] = this.template[p];
  26. this.frameDelayCd = this.frameDelay;
  27. this.setSprite();
  28. },
  29. setSprite: function () {
  30. renderer.setSprite({
  31. sprite: this.obj.sprite,
  32. cell: (this.row * 8) + this.col + this.frame,
  33. sheetName: this.spritesheet || this.sheet
  34. });
  35. },
  36. update: function () {
  37. if (this.frameDelayCd > 0)
  38. this.frameDelayCd--;
  39. else {
  40. this.frameDelayCd = this.frameDelay;
  41. this.frame++;
  42. if (this.frame == this.frames) {
  43. this.loopCounter++;
  44. if (this.loopCounter == this.loop) {
  45. this.destroyed = true;
  46. return;
  47. }
  48. this.frame = 0;
  49. }
  50. }
  51. this.setSprite();
  52. },
  53. destroy: function () {
  54. this.obj.sprite.texture = this.oldTexture;
  55. }
  56. };
  57. });