Skip to content

Commit 105a223

Browse files
committed
Frames can now set the alpha and visible properties of the sprites. Frame.onUpdate now called.
1 parent c4924fb commit 105a223

4 files changed

Lines changed: 53 additions & 12 deletions

File tree

v3/src/animation/AnimationFrame.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var AnimationFrame = function (index, frame, duration, onUpdate)
1+
var AnimationFrame = function (index, frame)
22
{
33
// The index of this frame within the Animation.frames array
44
this.index = index;
@@ -16,13 +16,21 @@ var AnimationFrame = function (index, frame, duration, onUpdate)
1616
this.nextFrame = null;
1717

1818
// Additional time (in ms) this frame should appear for - added onto the msPerFrame
19-
this.duration = duration;
19+
this.duration = 0;
2020

2121
// What % through the animation progress is this frame?
2222
this.progress = 0;
2323

2424
// Callback if this frame gets displayed
25-
this.onUpdate = onUpdate;
25+
this.onUpdate = null;
26+
27+
// When this frame hits, set sprite.alpha to this
28+
this.setAlpha = false;
29+
this.alpha = 1;
30+
31+
// When this frame hits, set sprite.visible to this
32+
this.setVisible = false;
33+
this.visible = false;
2634
};
2735

2836
AnimationFrame.prototype.constructor = AnimationFrame;

v3/src/animation/AnimationManager.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,20 @@ AnimationManager.prototype = {
4444
// { key: textureKey, frame: textureFrame },
4545
// { key: textureKey, frame: textureFrame, duration: float },
4646
// { key: textureKey, frame: textureFrame, onUpdate: function }
47-
// { key: textureKey, frame: textureFrame, flipX: boolean, flipY: boolean }
4847
// { key: textureKey, frame: textureFrame, alpha: float }
4948
// { key: textureKey, frame: textureFrame, visible: boolean }
50-
// ],
51-
// framerate: integer,
52-
// duration: float (seconds, optional, ignored if framerate is set),
53-
// skipMissedFrames: boolean,
49+
// ]
50+
// framerate: integer
51+
// duration: float (seconds, optional, ignored if framerate is set)
52+
// skipMissedFrames: boolean
5453
// delay: integer
5554
// repeat: -1 = forever, otherwise integer
5655
// repeatDelay: integer
5756
// yoyo: boolean
5857
// hideOnComplete: boolean
5958
// onStart: function
6059
// onRepeat: function
61-
// onComplete: function,
60+
// onComplete: function
6261
// transitions: [
6362
// {
6463
// key: string <- key of the animation to blend with,

v3/src/animation/frame/GetFrames.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,27 @@ var GetFrames = function (textureManager, frames)
3131
var frame = GetObjectValue(item, 'frame', 0);
3232
var duration = GetObjectValue(item, 'duration', 0);
3333
var onUpdate = GetObjectValue(item, 'onUpdate', null);
34+
var alpha = GetObjectValue(item, 'alpha', null);
35+
var visible = GetObjectValue(item, 'visible', null);
3436

3537
var textureFrame = textureManager.getFrame(key, frame);
3638

37-
animationFrame = new AnimationFrame(index, textureFrame, duration, onUpdate);
39+
animationFrame = new AnimationFrame(index, textureFrame);
40+
41+
animationFrame.duration = duration;
42+
animationFrame.onUpdate = onUpdate;
43+
44+
if (alpha !== null)
45+
{
46+
animationFrame.setAlpha = true;
47+
animationFrame.alpha = alpha;
48+
}
49+
50+
if (visible !== null)
51+
{
52+
animationFrame.setVisible = true;
53+
animationFrame.visible = visible;
54+
}
3855

3956
animationFrame.isFirst = (!prev);
4057

v3/src/components/Animation.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,27 @@ Animation.prototype = {
5353

5454
updateFrame: function (animationFrame)
5555
{
56+
var sprite = this.parent;
57+
5658
this.currentFrame = animationFrame;
5759

58-
this.parent.texture = animationFrame.frame.texture;
59-
this.parent.frame = animationFrame.frame;
60+
sprite.texture = animationFrame.frame.texture;
61+
sprite.frame = animationFrame.frame;
62+
63+
if (animationFrame.setAlpha)
64+
{
65+
sprite.alpha = animationFrame.alpha;
66+
}
67+
68+
if (animationFrame.setVisible)
69+
{
70+
sprite.visible = animationFrame.visible;
71+
}
72+
73+
if (animationFrame.onUpdate)
74+
{
75+
animationFrame.onUpdate(sprite, animationFrame);
76+
}
6077
},
6178

6279
load: function (key, startFrame)

0 commit comments

Comments
 (0)