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.
 
 
 

78 lines
1.3 KiB

  1. define([
  2. 'js/rendering/renderer'
  3. ], function (
  4. renderer
  5. ) {
  6. return {
  7. type: 'sprite',
  8. alpha: 1,
  9. tint: undefined,
  10. layerName: undefined,
  11. sheetName: undefined,
  12. sprite: undefined,
  13. init: function (blueprint) {
  14. this.buildSprite();
  15. },
  16. buildSprite: async function () {
  17. const { layerName, sheetName, cell, container } = this;
  18. this.sprite = await renderer.buildSpriteAsync({
  19. sheetName,
  20. cell,
  21. container,
  22. layerName,
  23. spriteConfig: {
  24. visible: false
  25. }
  26. });
  27. },
  28. update: function () {
  29. const { sprite, obj } = this;
  30. if (!sprite)
  31. return;
  32. let x = (obj.x * scale) + (obj.offsetX || 0);
  33. let y = (obj.y * scale) + (obj.offsetY || 0);
  34. const width = (obj?.transform?.width ?? obj.width) * scaleMult;
  35. const height = (obj?.transform?.height ?? obj.height) * scaleMult;
  36. Object.entries({
  37. x,
  38. y,
  39. visible: obj.isVisible,
  40. width: width,
  41. height: height
  42. }).forEach(([k, v]) => {
  43. if (sprite[k] !== v && v !== undefined)
  44. sprite[k] = v;
  45. });
  46. [
  47. 'alpha',
  48. 'tint'
  49. ].forEach(p => {
  50. const value = this[p];
  51. if (sprite[p] !== value && value !== undefined)
  52. sprite[p] = value;
  53. });
  54. },
  55. destroy: function () {
  56. const { sprite } = this;
  57. if (!sprite)
  58. return;
  59. sprite.parent.removeChild(sprite);
  60. }
  61. };
  62. });