babylon.sprite.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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.size = 1.0;
  8. this.angle = 0;
  9. this.cellIndex = 0;
  10. this.invertU = 0;
  11. this.invertV = 0;
  12. this._animationStarted = false;
  13. this._loopAnimation = false;
  14. this._fromIndex = 0;
  15. this._toIndex = 0;
  16. this._delay = 0;
  17. this._direction = 1;
  18. this._frameCount = 0;
  19. this._time = 0;
  20. this._manager = manager;
  21. this._manager.sprites.push(this);
  22. this.position = BABYLON.Vector3.Zero();
  23. }
  24. Sprite.prototype.playAnimation = function (from, to, loop, delay) {
  25. this._fromIndex = from;
  26. this._toIndex = to;
  27. this._loopAnimation = loop;
  28. this._delay = delay;
  29. this._animationStarted = true;
  30. this._direction = from < to ? 1 : -1;
  31. this.cellIndex = from;
  32. this._time = 0;
  33. };
  34. Sprite.prototype.stopAnimation = function () {
  35. this._animationStarted = false;
  36. };
  37. Sprite.prototype._animate = function (deltaTime) {
  38. if (!this._animationStarted)
  39. return;
  40. this._time += deltaTime;
  41. if (this._time > this._delay) {
  42. this._time = this._time % this._delay;
  43. this.cellIndex += this._direction;
  44. if (this.cellIndex == this._toIndex) {
  45. if (this._loopAnimation) {
  46. this.cellIndex = this._fromIndex;
  47. } else {
  48. this._animationStarted = false;
  49. if (this.disposeWhenFinishedAnimating) {
  50. this.dispose();
  51. }
  52. }
  53. }
  54. }
  55. };
  56. Sprite.prototype.dispose = function () {
  57. for (var i = 0; i < this._manager.sprites.length; i++) {
  58. if (this._manager.sprites[i] == this) {
  59. this._manager.sprites.splice(i, 1);
  60. }
  61. }
  62. };
  63. return Sprite;
  64. })();
  65. BABYLON.Sprite = Sprite;
  66. })(BABYLON || (BABYLON = {}));
  67. //# sourceMappingURL=babylon.sprite.js.map