mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 13:13:43 +00:00
Frames can now set the alpha and visible properties of the sprites. Frame.onUpdate now called.
This commit is contained in:
parent
c4924fbd70
commit
105a2234e7
4 changed files with 53 additions and 12 deletions
|
@ -1,4 +1,4 @@
|
|||
var AnimationFrame = function (index, frame, duration, onUpdate)
|
||||
var AnimationFrame = function (index, frame)
|
||||
{
|
||||
// The index of this frame within the Animation.frames array
|
||||
this.index = index;
|
||||
|
@ -16,13 +16,21 @@ var AnimationFrame = function (index, frame, duration, onUpdate)
|
|||
this.nextFrame = null;
|
||||
|
||||
// Additional time (in ms) this frame should appear for - added onto the msPerFrame
|
||||
this.duration = duration;
|
||||
this.duration = 0;
|
||||
|
||||
// What % through the animation progress is this frame?
|
||||
this.progress = 0;
|
||||
|
||||
// Callback if this frame gets displayed
|
||||
this.onUpdate = onUpdate;
|
||||
this.onUpdate = null;
|
||||
|
||||
// When this frame hits, set sprite.alpha to this
|
||||
this.setAlpha = false;
|
||||
this.alpha = 1;
|
||||
|
||||
// When this frame hits, set sprite.visible to this
|
||||
this.setVisible = false;
|
||||
this.visible = false;
|
||||
};
|
||||
|
||||
AnimationFrame.prototype.constructor = AnimationFrame;
|
||||
|
|
|
@ -44,13 +44,12 @@ AnimationManager.prototype = {
|
|||
// { key: textureKey, frame: textureFrame },
|
||||
// { key: textureKey, frame: textureFrame, duration: float },
|
||||
// { key: textureKey, frame: textureFrame, onUpdate: function }
|
||||
// { key: textureKey, frame: textureFrame, flipX: boolean, flipY: boolean }
|
||||
// { key: textureKey, frame: textureFrame, alpha: float }
|
||||
// { key: textureKey, frame: textureFrame, visible: boolean }
|
||||
// ],
|
||||
// framerate: integer,
|
||||
// duration: float (seconds, optional, ignored if framerate is set),
|
||||
// skipMissedFrames: boolean,
|
||||
// ]
|
||||
// framerate: integer
|
||||
// duration: float (seconds, optional, ignored if framerate is set)
|
||||
// skipMissedFrames: boolean
|
||||
// delay: integer
|
||||
// repeat: -1 = forever, otherwise integer
|
||||
// repeatDelay: integer
|
||||
|
@ -58,7 +57,7 @@ AnimationManager.prototype = {
|
|||
// hideOnComplete: boolean
|
||||
// onStart: function
|
||||
// onRepeat: function
|
||||
// onComplete: function,
|
||||
// onComplete: function
|
||||
// transitions: [
|
||||
// {
|
||||
// key: string <- key of the animation to blend with,
|
||||
|
|
|
@ -31,10 +31,27 @@ var GetFrames = function (textureManager, frames)
|
|||
var frame = GetObjectValue(item, 'frame', 0);
|
||||
var duration = GetObjectValue(item, 'duration', 0);
|
||||
var onUpdate = GetObjectValue(item, 'onUpdate', null);
|
||||
var alpha = GetObjectValue(item, 'alpha', null);
|
||||
var visible = GetObjectValue(item, 'visible', null);
|
||||
|
||||
var textureFrame = textureManager.getFrame(key, frame);
|
||||
|
||||
animationFrame = new AnimationFrame(index, textureFrame, duration, onUpdate);
|
||||
animationFrame = new AnimationFrame(index, textureFrame);
|
||||
|
||||
animationFrame.duration = duration;
|
||||
animationFrame.onUpdate = onUpdate;
|
||||
|
||||
if (alpha !== null)
|
||||
{
|
||||
animationFrame.setAlpha = true;
|
||||
animationFrame.alpha = alpha;
|
||||
}
|
||||
|
||||
if (visible !== null)
|
||||
{
|
||||
animationFrame.setVisible = true;
|
||||
animationFrame.visible = visible;
|
||||
}
|
||||
|
||||
animationFrame.isFirst = (!prev);
|
||||
|
||||
|
|
|
@ -53,10 +53,27 @@ Animation.prototype = {
|
|||
|
||||
updateFrame: function (animationFrame)
|
||||
{
|
||||
var sprite = this.parent;
|
||||
|
||||
this.currentFrame = animationFrame;
|
||||
|
||||
this.parent.texture = animationFrame.frame.texture;
|
||||
this.parent.frame = animationFrame.frame;
|
||||
sprite.texture = animationFrame.frame.texture;
|
||||
sprite.frame = animationFrame.frame;
|
||||
|
||||
if (animationFrame.setAlpha)
|
||||
{
|
||||
sprite.alpha = animationFrame.alpha;
|
||||
}
|
||||
|
||||
if (animationFrame.setVisible)
|
||||
{
|
||||
sprite.visible = animationFrame.visible;
|
||||
}
|
||||
|
||||
if (animationFrame.onUpdate)
|
||||
{
|
||||
animationFrame.onUpdate(sprite, animationFrame);
|
||||
}
|
||||
},
|
||||
|
||||
load: function (key, startFrame)
|
||||
|
|
Loading…
Reference in a new issue