mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 06:28:30 +00:00
Lots of work updating the Animation system.
This commit is contained in:
parent
ea0af28983
commit
0ed1de6546
5 changed files with 62 additions and 16 deletions
|
@ -3,6 +3,12 @@ var AnimationFrame = function (frame, duration, onUpdate)
|
|||
// Texture Frame
|
||||
this.frame = frame;
|
||||
|
||||
// The frame that comes before this one in the animation (if any)
|
||||
this.prevFrame = null;
|
||||
|
||||
// The frame that comes after this one in the animation (if any)
|
||||
this.nextFrame = null;
|
||||
|
||||
// Duration this frame should appear for (modifier to fps rate)
|
||||
this.duration = duration;
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ var AnimationManager = function (game)
|
|||
{
|
||||
this.game = game;
|
||||
|
||||
this.textureManager = game.textures;
|
||||
this.textureManager = null;
|
||||
|
||||
this.anims = new Map();
|
||||
};
|
||||
|
@ -31,6 +31,11 @@ AnimationManager.prototype.constructor = AnimationManager;
|
|||
|
||||
AnimationManager.prototype = {
|
||||
|
||||
boot: function (textureManager)
|
||||
{
|
||||
this.textureManager = textureManager;
|
||||
},
|
||||
|
||||
// add frame name based animation
|
||||
// add frame index based animation
|
||||
// add bone based animation
|
||||
|
@ -61,7 +66,7 @@ AnimationManager.prototype = {
|
|||
// ]
|
||||
// }
|
||||
|
||||
add: function (key, config)
|
||||
create: function (key, config)
|
||||
{
|
||||
if (this.anims.has(key))
|
||||
{
|
||||
|
@ -79,6 +84,19 @@ AnimationManager.prototype = {
|
|||
get: function (key)
|
||||
{
|
||||
return this.anims.get(key);
|
||||
},
|
||||
|
||||
// Load an Animation into a Game Objects Animation Component
|
||||
load: function (child, key, startFrame)
|
||||
{
|
||||
var anim = this.get(key);
|
||||
|
||||
if (anim)
|
||||
{
|
||||
anim.load(child, startFrame);
|
||||
}
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -23,10 +23,9 @@ var Animation = function (manager, key, config)
|
|||
// onRepeat: function
|
||||
// onComplete: function,
|
||||
|
||||
this.frames = [];
|
||||
|
||||
// Extract all the frame data into the frames array
|
||||
GetFrames(this, GetObjectValue(config, 'frames', []), this.frames);
|
||||
|
||||
this.frames = GetFrames(manager.textureManager, GetObjectValue(config, 'frames', []));
|
||||
|
||||
this.framerate = GetObjectValue(config, 'framerate', 24);
|
||||
|
||||
|
@ -62,19 +61,29 @@ Animation.prototype.constructor = Animation;
|
|||
|
||||
Animation.prototype = {
|
||||
|
||||
start: function ()
|
||||
load: function (component, startFrame)
|
||||
{
|
||||
if (startFrame >= this.frames.length)
|
||||
{
|
||||
startFrame = 0;
|
||||
}
|
||||
|
||||
component.currentAnim = this;
|
||||
component.currentFrame = this.frames[startFrame];
|
||||
},
|
||||
|
||||
update: function (elapsed)
|
||||
checkFrame: function (index)
|
||||
{
|
||||
|
||||
return (index < this.frames.length);
|
||||
},
|
||||
|
||||
stop: function ()
|
||||
setFrame: function (timestamp, child)
|
||||
{
|
||||
// Work out which frame should be set next on the child, and set it
|
||||
|
||||
|
||||
|
||||
return child;
|
||||
},
|
||||
|
||||
destroy: function ()
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
var AnimationFrame = require('../AnimationFrame');
|
||||
var GetObjectValue = require('../../utils/object/GetObjectValue');
|
||||
|
||||
var GetFrames = function (animation, frames, out)
|
||||
var GetFrames = function (textureManager, frames)
|
||||
{
|
||||
if (out === undefined) { out = []; }
|
||||
|
||||
var textureManager = animation.manager.textureManager;
|
||||
|
||||
// frames: [
|
||||
// { key: textureKey, frame: textureFrame },
|
||||
// { key: textureKey, frame: textureFrame, duration: float },
|
||||
// { key: textureKey, frame: textureFrame, onUpdate: function }
|
||||
// ],
|
||||
|
||||
// console.table(frames);
|
||||
|
||||
var out = [];
|
||||
var prev;
|
||||
|
||||
for (var i = 0; i < frames.length; i++)
|
||||
{
|
||||
var item = frames[i];
|
||||
|
@ -30,7 +31,19 @@ var GetFrames = function (animation, frames, out)
|
|||
|
||||
var textureFrame = textureManager.getFrame(key, frame);
|
||||
|
||||
out.push(new AnimationFrame(textureFrame, duration, onUpdate));
|
||||
var animationFrame = new AnimationFrame(textureFrame, duration, onUpdate);
|
||||
|
||||
// The previously created animationFrame
|
||||
if (prev)
|
||||
{
|
||||
prev.nextFrame = animationFrame;
|
||||
|
||||
animationFrame.prevFrame = prev;
|
||||
}
|
||||
|
||||
out.push(animationFrame);
|
||||
|
||||
prev = animationFrame;
|
||||
}
|
||||
|
||||
return out;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var CHECKSUM = {
|
||||
build: '64e60870-194e-11e7-b411-f1e5026f0a49'
|
||||
build: '0b881830-1986-11e7-85f8-f3dbabc79515'
|
||||
};
|
||||
module.exports = CHECKSUM;
|
Loading…
Add table
Reference in a new issue