Lots more work on the Animation Manager. New Animation format defined, properties added, frame splitter added and starting to plan out update loop.

This commit is contained in:
Richard Davey 2017-04-04 16:32:33 +01:00
parent acea677424
commit 679dd1091e
5 changed files with 179 additions and 2 deletions

View file

@ -0,0 +1,25 @@
var AnimationFrame = function (frame, duration, onUpdate)
{
// Texture Frame
this.frame = frame;
// Duration this frame should appear for (modifier to fps rate)
this.duration = duration;
// Callback if this frame gets displayed
this.onUpdate = onUpdate;
};
AnimationFrame.prototype.constructor = AnimationFrame;
AnimationFrame.prototype = {
destroy: function ()
{
this.frame = undefined;
this.onUpdate = undefined;
}
};
module.exports = AnimationFrame;

View file

@ -4,6 +4,7 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Animation = require('./frame/Animation');
var Map = require('../structs/Map');
/**
@ -21,6 +22,8 @@ var AnimationManager = function (game)
{
this.game = game;
this.textureManager = game.textures;
this.anims = new Map();
};
@ -33,7 +36,32 @@ AnimationManager.prototype = {
// add bone based animation
// add animation from json data
add: function (key, frames, loop)
// {
// frames: [
// { key: textureKey, frame: textureFrame },
// { key: textureKey, frame: textureFrame, duration: float },
// { key: textureKey, frame: textureFrame, onUpdate: function }
// ],
// framerate: integer,
// duration: float (seconds, optional, ignored if framerate is set),
// skipMissedFrames: boolean,
// delay: integer
// repeat: -1 = forever, otherwise integer
// repeatDelay: integer
// yoyo: boolean,
// onStart: function
// onRepeat: function
// onComplete: function,
//
// transitions: [
// {
// key: string <- key of the animation to blend with,
// frames: [] <- play these frames before starting key
// }
// ]
// }
add: function (key, config)
{
if (this.anims.has(key))
{
@ -41,7 +69,11 @@ AnimationManager.prototype = {
return;
}
var anim = new Animation(this, key, config);
this.anims.set(key, anim);
return anim;
},
get: function (key)

View file

@ -0,0 +1,81 @@
var GetObjectValue = require('../../utils/object/GetObjectValue');
var GetFrames = require('./GetFrames');
var Animation = function (manager, config)
{
this.manager = manager;
// frames: [
// { key: textureKey, frame: textureFrame },
// { key: textureKey, frame: textureFrame, duration: float },
// { key: textureKey, frame: textureFrame, onUpdate: function }
// ],
// framerate: integer,
// duration: float (seconds, optional, ignored if framerate is set),
// skipMissedFrames: boolean,
// delay: integer
// repeat: -1 = forever, otherwise integer
// repeatDelay: integer
// yoyo: boolean,
// onStart: function
// onRepeat: function
// onComplete: function,
this.frames = GetFrames(this, GetObjectValue(config, 'frames', []));
this.framerate = GetObjectValue(config, 'framerate', 24);
this.duration = GetObjectValue(config, 'duration', null);
if (this.duration === null)
{
this.duration = this.framerate * this.frames.length;
}
else
{
// Duration controls framerate
}
this.skipMissedFrames = GetObjectValue(config, 'skipMissedFrames', true);
// Delay before starting playback (in seconds)
this.delay = GetObjectValue(config, 'delay', 0);
this.repeat = GetObjectValue(config, 'repeat', 0);
this.repeatDelay = GetObjectValue(config, 'repeatDelay', 0);
this.yoyo = GetObjectValue(config, 'yoyo', false);
this.onStart = GetObjectValue(config, 'onStart', false);
this.onRepeat = GetObjectValue(config, 'onRepeat', false);
this.onComplete = GetObjectValue(config, 'onComplete', false);
this.onStop = GetObjectValue(config, 'onStop', false);
};
Animation.prototype.constructor = Animation;
Animation.prototype = {
start: function ()
{
},
update: function (elapsed)
{
},
stop: function ()
{
},
destroy: function ()
{
}
};
module.exports = Animation;

View file

@ -0,0 +1,39 @@
var AnimationFrame = require('../AnimationFrame');
var GetObjectValue = require('../../utils/object/GetObjectValue');
var GetFrames = function (animation, frames)
{
var out = [];
var textureManager = animation.manager.textureManager;
// frames: [
// { key: textureKey, frame: textureFrame },
// { key: textureKey, frame: textureFrame, duration: float },
// { key: textureKey, frame: textureFrame, onUpdate: function }
// ],
for (var i = 0; i < frames.length; i++)
{
var item = frames[i];
var key = GetObjectValue(item, 'key', null);
if (!key)
{
continue;
}
var frame = GetObjectValue(item, 'frame', 0);
var duration = GetObjectValue(item, 'duration', 0);
var onUpdate = GetObjectValue(item, 'onUpdate', null);
var textureFrame = textureManager.getFrame(key, frame);
out.push(new AnimationFrame(textureFrame, duration, onUpdate));
}
return out;
};
module.exports = GetFrames;

View file

@ -1,4 +1,4 @@
var CHECKSUM = {
build: '74477d20-1936-11e7-8c5f-29386239866f'
build: '9c151b40-194b-11e7-b6bd-adc4d80a51e2'
};
module.exports = CHECKSUM;