Skip to content

Commit ed5eda4

Browse files
committed
Optmized the addFrameAt method.
1 parent 12d3771 commit ed5eda4

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

v3/src/animation/frame/Animation.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,28 @@ Animation.prototype = {
148148

149149
var newFrames = GetFrames(this.manager.textureManager, config);
150150

151-
if (newFrames.length > 0)
151+
if (newFrames.length === 0)
152152
{
153-
var pre = this.frames.slice(0, index);
154-
var post = this.frames.slice(index);
153+
if (index === 0)
154+
{
155+
this.frames = newFrames.concat(this.frames);
156+
}
157+
else if (index === this.frames.length)
158+
{
159+
this.frames = this.frames.concat(newFrames);
160+
}
161+
else
162+
{
163+
var pre = this.frames.slice(0, index);
164+
var post = this.frames.slice(index);
165+
166+
this.frames = pre.concat(newFrames, post);
167+
}
155168

156-
this.frames = pre.concat(newFrames, post);
169+
this.updateFrameSequence();
157170
}
158171

159-
return this.updateFrameSequence();
172+
return this;
160173
},
161174

162175
updateFrameSequence: function ()

0 commit comments

Comments
 (0)