Skip to content

Commit 4ad8795

Browse files
committed
Added Animation.removeFrame, removeFrameAt and getFrameAt.
1 parent ed5eda4 commit 4ad8795

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

v3/src/animation/frame/Animation.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,18 @@ Animation.prototype = {
137137
this.paused = false;
138138
},
139139

140+
// config = Array of Animation config objects, like:
141+
// [
142+
// { key: 'gems', frame: 'diamond0001', [duration], [visible], [onUpdate] }
143+
// ]
144+
145+
// Add frames to the end of the animation
140146
addFrame: function (config)
141147
{
142-
return this.addFrameAt(0, config);
148+
return this.addFrameAt(this.frames.length, config);
143149
},
144150

151+
// Add frame/s into the animation
145152
addFrameAt: function (index, config)
146153
{
147154
if (index === undefined) { index = 0; }
@@ -172,6 +179,33 @@ Animation.prototype = {
172179
return this;
173180
},
174181

182+
getFrameAt: function (index)
183+
{
184+
return this.frames[index];
185+
},
186+
187+
// Remove frame if it matches the given frame
188+
removeFrame: function (frame)
189+
{
190+
var index = this.frames.indexOf(frame);
191+
192+
if (index !== -1)
193+
{
194+
this.removeFrameAt(index);
195+
}
196+
197+
return this;
198+
},
199+
200+
removeFrameAt: function (index)
201+
{
202+
this.frames.splice(index, 1);
203+
204+
this.updateFrameSequence();
205+
206+
return this;
207+
},
208+
175209
updateFrameSequence: function ()
176210
{
177211
var len = this.frames.length;

v3/src/animation/frame/Frame.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,33 @@ var Frame = function (textureKey, textureFrame, index, frame)
1010
// Texture Frame
1111
this.frame = frame;
1212

13+
// Read-only
1314
this.isFirst = false;
15+
16+
// Read-only
1417
this.isLast = false;
1518

1619
// The frame that comes before this one in the animation (if any)
20+
// Read-only
1721
this.prevFrame = null;
1822

1923
// The frame that comes after this one in the animation (if any)
24+
// Read-only
2025
this.nextFrame = null;
2126

2227
// Additional time (in ms) this frame should appear for - added onto the msPerFrame
2328
this.duration = 0;
2429

2530
// What % through the animation progress is this frame?
31+
// Read-only
2632
this.progress = 0;
2733

2834
// Callback if this frame gets displayed
2935
this.onUpdate = null;
3036

3137
// When this frame hits, set sprite.visible to this
3238
this.setVisible = false;
39+
3340
this.visible = false;
3441
};
3542

0 commit comments

Comments
 (0)