babylon.sprite.js 2.5 KB

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