babylon.sprite.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var Sprite = (function () {
  4. function Sprite(name, manager) {
  5. this.name = name;
  6. this.color = new BABYLON.Color4(1.0, 1.0, 1.0, 1.0);
  7. this.width = 1.0;
  8. this.height = 1.0;
  9. this.angle = 0;
  10. this.cellIndex = 0;
  11. this.invertU = 0;
  12. this.invertV = 0;
  13. this.animations = new Array();
  14. this._animationStarted = false;
  15. this._loopAnimation = false;
  16. this._fromIndex = 0;
  17. this._toIndex = 0;
  18. this._delay = 0;
  19. this._direction = 1;
  20. this._frameCount = 0;
  21. this._time = 0;
  22. this._manager = manager;
  23. this._manager.sprites.push(this);
  24. this.position = BABYLON.Vector3.Zero();
  25. }
  26. Object.defineProperty(Sprite.prototype, "size", {
  27. get: function () {
  28. return this.width;
  29. },
  30. set: function (value) {
  31. this.width = value;
  32. this.height = value;
  33. },
  34. enumerable: true,
  35. configurable: true
  36. });
  37. Sprite.prototype.playAnimation = function (from, to, loop, delay) {
  38. this._fromIndex = from;
  39. this._toIndex = to;
  40. this._loopAnimation = loop;
  41. this._delay = delay;
  42. this._animationStarted = true;
  43. this._direction = from < to ? 1 : -1;
  44. this.cellIndex = from;
  45. this._time = 0;
  46. };
  47. Sprite.prototype.stopAnimation = function () {
  48. this._animationStarted = false;
  49. };
  50. Sprite.prototype._animate = function (deltaTime) {
  51. if (!this._animationStarted)
  52. return;
  53. this._time += deltaTime;
  54. if (this._time > this._delay) {
  55. this._time = this._time % this._delay;
  56. this.cellIndex += this._direction;
  57. if (this.cellIndex == this._toIndex) {
  58. if (this._loopAnimation) {
  59. this.cellIndex = this._fromIndex;
  60. }
  61. else {
  62. this._animationStarted = false;
  63. if (this.disposeWhenFinishedAnimating) {
  64. this.dispose();
  65. }
  66. }
  67. }
  68. }
  69. };
  70. Sprite.prototype.dispose = function () {
  71. for (var i = 0; i < this._manager.sprites.length; i++) {
  72. if (this._manager.sprites[i] == this) {
  73. this._manager.sprites.splice(i, 1);
  74. }
  75. }
  76. };
  77. return Sprite;
  78. })();
  79. BABYLON.Sprite = Sprite;
  80. })(BABYLON || (BABYLON = {}));
  81. //# sourceMappingURL=babylon.sprite.js.map