babylon.sprite.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. }
  49. else {
  50. this._animationStarted = false;
  51. if (this.disposeWhenFinishedAnimating) {
  52. this.dispose();
  53. }
  54. }
  55. }
  56. }
  57. };
  58. Sprite.prototype.dispose = function () {
  59. for (var i = 0; i < this._manager.sprites.length; i++) {
  60. if (this._manager.sprites[i] == this) {
  61. this._manager.sprites.splice(i, 1);
  62. }
  63. }
  64. };
  65. return Sprite;
  66. })();
  67. BABYLON.Sprite = Sprite;
  68. })(BABYLON || (BABYLON = {}));
  69. //# sourceMappingURL=babylon.sprite.js.map