forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTweenManager.js
More file actions
147 lines (104 loc) · 3.06 KB
/
Copy pathTweenManager.js
File metadata and controls
147 lines (104 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/**
* Phaser - TweenManager
*
* Phaser.Game has a single instance of the TweenManager through which all Tween objects are created and updated.
* Tweens are hooked into the game clock and pause system, adjusting based on the game state.
*
* TweenManager is based heavily on tween.js by sole (http://soledadpenades.com).
* The difference being that tweens belong to a games instance of TweenManager, rather than to a global TWEEN object.
* It also has callbacks swapped for Signals and a few issues patched with regard to properties and completion errors.
* Please see https://github.com/sole/tween.js for a full list of contributors.
*/
Phaser.TweenManager = function (game) {
this.game = game;
this._tweens = [];
};
Phaser.TweenManager.prototype = {
REVISION: '11dev',
/**
* Get all the tween objects in an array.
* @return {Phaser.Tween[]} Array with all tween objects.
*/
getAll: function () {
return _tweens;
},
/**
* Remove all tween objects.
*/
removeAll: function () {
_tweens = [];
},
/**
* Add a new tween into the TweenManager.
*
* @param tween {Phaser.Tween} The tween object you want to add.
* @return {Phaser.Tween} The tween object you added to the manager.
*/
add: function ( tween ) {
_tweens.push( tween );
},
/**
* Create a tween object for a specific object. The object can be any JavaScript object or Phaser object such as Sprite.
*
* @param obj {object} Object the tween will be run on.
* @param [localReference] {bool} If true the tween will be stored in the object.tween property so long as it exists. If already set it'll be over-written.
* @return {Phaser.Tween} The newly created tween object.
*/
create: function (object, localReference) {
if (typeof localReference === "undefined") { localReference = false; }
if (localReference)
{
object['tween'] = new Phaser.Tween(object, this.game);
return object['tween'];
}
else
{
return new Phaser.Tween(object, this.game);
}
},
/**
* Remove a tween from this manager.
*
* @param tween {Phaser.Tween} The tween object you want to remove.
*/
remove: function ( tween ) {
var i = _tweens.indexOf( tween );
if ( i !== -1 ) {
_tweens.splice( i, 1 );
}
},
/**
* Update all the tween objects you added to this manager.
*
* @return {bool} Return false if there's no tween to update, otherwise return true.
*/
update: function () {
if ( _tweens.length === 0 ) return false;
var i = 0, numTweens = _tweens.length;
while ( i < numTweens ) {
if ( _tweens[ i ].update( this.game.time.now ) ) {
i ++;
} else {
_tweens.splice( i, 1 );
numTweens --;
}
}
return true;
},
/**
* Pauses all currently running tweens.
*/
pauseAll: function () {
for (var i = this._tweens.length - 1; i >= 0; i--) {
this._tweens[i].pause();
};
},
/**
* Pauses all currently paused tweens.
*/
resumeAll: function () {
for (var i = this._tweens.length - 1; i >= 0; i--) {
this._tweens[i].resume();
};
}
};