mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 06:28:30 +00:00
Working through setting the Tween values.
This commit is contained in:
parent
050948aa28
commit
bd462e29bd
3 changed files with 120 additions and 4 deletions
23
v3/src/tween/GetEaseFunction.js
Normal file
23
v3/src/tween/GetEaseFunction.js
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
var EaseMap = require('../math/easing/EaseMap');
|
||||||
|
|
||||||
|
var GetEaseFunction = function (ease)
|
||||||
|
{
|
||||||
|
if (typeof ease === 'string' && EaseMap.hasOwnProperty(ease))
|
||||||
|
{
|
||||||
|
// String based look-up
|
||||||
|
return EaseMap[ease];
|
||||||
|
}
|
||||||
|
else if (typeof ease === 'function')
|
||||||
|
{
|
||||||
|
// Custom function
|
||||||
|
return ease;
|
||||||
|
}
|
||||||
|
else if (Array.isArray(ease) && ease.length === 4)
|
||||||
|
{
|
||||||
|
// Bezier function (TODO)
|
||||||
|
}
|
||||||
|
|
||||||
|
return EaseMap.Power0;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = GetEaseFunction;
|
|
@ -1,4 +1,6 @@
|
||||||
var GetValue = require('../utils/object/GetValue');
|
var GetValue = require('../utils/object/GetValue');
|
||||||
|
var GetEaseFunction = require('./GetEaseFunction');
|
||||||
|
var CloneObject = require('../utils/object/Clone');
|
||||||
var TweenData = require('./TweenData');
|
var TweenData = require('./TweenData');
|
||||||
|
|
||||||
var RESERVED = [ 'targets', 'ease', 'duration', 'yoyo', 'repeat', 'loop', 'paused', 'useFrames', 'offset' ];
|
var RESERVED = [ 'targets', 'ease', 'duration', 'yoyo', 'repeat', 'loop', 'paused', 'useFrames', 'offset' ];
|
||||||
|
@ -69,7 +71,13 @@ var Tween = function (manager, config)
|
||||||
|
|
||||||
this.targets = this.setTargets(GetValue(config, 'targets', null));
|
this.targets = this.setTargets(GetValue(config, 'targets', null));
|
||||||
|
|
||||||
this.ease;
|
// The properties on the targets that are being tweened.
|
||||||
|
// The properties are tween simultaneously.
|
||||||
|
// This object contains the properties which each has an array of TweenData objects,
|
||||||
|
// that are updated in sequence.
|
||||||
|
this.props = {};
|
||||||
|
|
||||||
|
this.ease = GetEaseFunction(GetValue(config, 'ease', 'Power0'));
|
||||||
|
|
||||||
this.duration = GetValue(config, 'duration', 1000);
|
this.duration = GetValue(config, 'duration', 1000);
|
||||||
|
|
||||||
|
@ -78,9 +86,29 @@ var Tween = function (manager, config)
|
||||||
|
|
||||||
this.yoyo = GetValue(config, 'yoyo', false);
|
this.yoyo = GetValue(config, 'yoyo', false);
|
||||||
this.repeat = GetValue(config, 'repeat', 0);
|
this.repeat = GetValue(config, 'repeat', 0);
|
||||||
|
this.delay = GetValue(config, 'delay', 0);
|
||||||
|
this.onCompleteDelay = GetValue(config, 'onCompleteDelay', 0);
|
||||||
|
|
||||||
// same as repeat -1 (if set, overrides repeat value)
|
// Short-cut for repeat -1 (if set, overrides repeat value)
|
||||||
this.loop = GetValue(config, 'loop', undefined);
|
this.loop = GetValue(config, 'loop', false);
|
||||||
|
|
||||||
|
if (this.repeat === -1)
|
||||||
|
{
|
||||||
|
this.loop = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.defaultTweenData = {
|
||||||
|
value: undefined,
|
||||||
|
progress: 0,
|
||||||
|
startTime: 0,
|
||||||
|
ease: this.ease,
|
||||||
|
duration: this.duration,
|
||||||
|
yoyo: this.yoyo,
|
||||||
|
repeat: this.repeat,
|
||||||
|
loop: this.loop,
|
||||||
|
delay: this.delay,
|
||||||
|
startAt: undefined
|
||||||
|
};
|
||||||
|
|
||||||
this.paused = GetValue(config, 'paused', false);
|
this.paused = GetValue(config, 'paused', false);
|
||||||
|
|
||||||
|
@ -104,6 +132,8 @@ var Tween = function (manager, config)
|
||||||
|
|
||||||
this.callbackScope;
|
this.callbackScope;
|
||||||
|
|
||||||
|
this.buildTweenData(config);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Tween.prototype.constructor = Tween;
|
Tween.prototype.constructor = Tween;
|
||||||
|
@ -112,6 +142,48 @@ Tween.prototype = {
|
||||||
|
|
||||||
// Move to own functions
|
// Move to own functions
|
||||||
|
|
||||||
|
getV: function (obj, key)
|
||||||
|
{
|
||||||
|
if (obj.hasOwnProperty(key))
|
||||||
|
{
|
||||||
|
return obj[key];
|
||||||
|
}
|
||||||
|
else if (this[key])
|
||||||
|
{
|
||||||
|
return this[key];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
buildTweenData: function (config)
|
||||||
|
{
|
||||||
|
// For now let's just assume `config.props` is being used:
|
||||||
|
|
||||||
|
// this.defaultTweenData = {
|
||||||
|
// value: undefined,
|
||||||
|
// progress: 0,
|
||||||
|
// startTime: 0,
|
||||||
|
// ease: this.ease,
|
||||||
|
// duration: this.duration,
|
||||||
|
// yoyo: this.yoyo,
|
||||||
|
// repeat: this.repeat,
|
||||||
|
// loop: this.loop,
|
||||||
|
// delay: this.delay,
|
||||||
|
// startAt: undefined
|
||||||
|
// };
|
||||||
|
|
||||||
|
for (var key in config.props)
|
||||||
|
{
|
||||||
|
var data = CloneObject(this.defaultTweenData);
|
||||||
|
|
||||||
|
this.props[key] =
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
update: function (timestep, delta)
|
||||||
|
{
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
setTargets: function (targets)
|
setTargets: function (targets)
|
||||||
{
|
{
|
||||||
if (typeof targets === 'function')
|
if (typeof targets === 'function')
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
|
/*
|
||||||
var TweenData = function (parent)
|
var TweenData = function (parent)
|
||||||
{
|
{
|
||||||
this.tween = parent;
|
this.tween = parent;
|
||||||
|
|
||||||
this.property;
|
this.property;
|
||||||
|
|
||||||
this.value;
|
this.value;
|
||||||
|
|
||||||
this.ease;
|
this.ease;
|
||||||
|
@ -23,6 +24,26 @@ TweenData.prototype = {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Could this just be a data bag?
|
||||||
|
|
||||||
|
var TweenData = function (config)
|
||||||
|
{
|
||||||
|
this.property = ;
|
||||||
|
|
||||||
|
this.value;
|
||||||
|
|
||||||
|
this.ease;
|
||||||
|
this.duration;
|
||||||
|
this.yoyo;
|
||||||
|
this.repeat;
|
||||||
|
this.delay;
|
||||||
|
this.startAt;
|
||||||
|
this.onCompleteDelay;
|
||||||
|
this.elasticity;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = TweenData;
|
module.exports = TweenData;
|
||||||
|
|
Loading…
Add table
Reference in a new issue