mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 13:43:26 +00:00
Number Tweens added for purely numeric tweens when you don't want to have to create local objects
This commit is contained in:
parent
df49b2d4af
commit
8be72cc9c0
2 changed files with 113 additions and 0 deletions
100
v3/src/tween/builder/NumberTweenBuilder.js
Normal file
100
v3/src/tween/builder/NumberTweenBuilder.js
Normal file
|
@ -0,0 +1,100 @@
|
|||
var Defaults = require('../tween/Defaults');
|
||||
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
|
||||
var GetBoolean = require('./GetBoolean');
|
||||
var GetEaseFunction = require('./GetEaseFunction');
|
||||
var GetNewValue = require('./GetNewValue');
|
||||
var GetValue = require('../../utils/object/GetValue');
|
||||
var GetValueOp = require('./GetValueOp');
|
||||
var Tween = require('../tween/Tween');
|
||||
var TweenData = require('../tween/TweenData');
|
||||
|
||||
var NumberTweenBuilder = function (parent, config, defaults)
|
||||
{
|
||||
if (defaults === undefined)
|
||||
{
|
||||
defaults = Defaults;
|
||||
}
|
||||
|
||||
// var tween = this.tweens.addCounter({
|
||||
// from: 100,
|
||||
// to: 200,
|
||||
// ... (normal tween properties)
|
||||
// })
|
||||
//
|
||||
// Then use it in your game via:
|
||||
//
|
||||
// tween.getValue()
|
||||
|
||||
var from = GetValue(config, 'from', 0);
|
||||
var to = GetValue(config, 'to', 1);
|
||||
|
||||
var targets = [{ value: from }];
|
||||
|
||||
var delay = GetNewValue(config, 'delay', defaults.delay);
|
||||
var duration = GetNewValue(config, 'duration', defaults.duration);
|
||||
var easeParams = GetValue(config, 'easeParams', defaults.easeParams);
|
||||
var ease = GetEaseFunction(GetValue(config, 'ease', defaults.ease), easeParams);
|
||||
var hold = GetNewValue(config, 'hold', defaults.hold);
|
||||
var repeat = GetNewValue(config, 'repeat', defaults.repeat);
|
||||
var repeatDelay = GetNewValue(config, 'repeatDelay', defaults.repeatDelay);
|
||||
var yoyo = GetBoolean(config, 'yoyo', defaults.yoyo);
|
||||
|
||||
var data = [];
|
||||
|
||||
var ops = GetValueOp('value', to);
|
||||
|
||||
var tweenData = TweenData(
|
||||
targets[0],
|
||||
'value',
|
||||
ops.getEnd,
|
||||
ops.getStart,
|
||||
ease,
|
||||
delay,
|
||||
duration,
|
||||
yoyo,
|
||||
hold,
|
||||
repeat,
|
||||
repeatDelay,
|
||||
false,
|
||||
false
|
||||
);
|
||||
|
||||
data.push(tweenData);
|
||||
|
||||
var tween = new Tween(parent, data, targets);
|
||||
|
||||
tween.offset = GetAdvancedValue(config, 'offset', null);
|
||||
tween.completeDelay = GetAdvancedValue(config, 'completeDelay', 0);
|
||||
tween.loop = Math.round(GetAdvancedValue(config, 'loop', 0));
|
||||
tween.loopDelay = Math.round(GetAdvancedValue(config, 'loopDelay', 0));
|
||||
tween.paused = GetBoolean(config, 'paused', false);
|
||||
tween.useFrames = GetBoolean(config, 'useFrames', false);
|
||||
|
||||
// Set the Callbacks
|
||||
var scope = GetValue(config, 'callbackScope', tween);
|
||||
|
||||
// Callback parameters: 0 = a reference to the Tween itself, 1 = the target/s of the Tween, ... your own params
|
||||
var tweenArray = [ tween, null ];
|
||||
|
||||
var callbacks = Tween.TYPES;
|
||||
|
||||
for (var i = 0; i < callbacks.length; i++)
|
||||
{
|
||||
var type = callbacks[i];
|
||||
|
||||
var callback = GetValue(config, type, false);
|
||||
|
||||
if (callback)
|
||||
{
|
||||
var callbackScope = GetValue(config, type + 'Scope', scope);
|
||||
var callbackParams = GetValue(config, type + 'Params', []);
|
||||
|
||||
// The null is reset to be the Tween target
|
||||
tween.setCallback(type, callback, tweenArray.concat(callbackParams), callbackScope);
|
||||
}
|
||||
}
|
||||
|
||||
return tween;
|
||||
};
|
||||
|
||||
module.exports = NumberTweenBuilder;
|
|
@ -2,6 +2,7 @@
|
|||
var Class = require('../../utils/Class');
|
||||
var TimelineBuilder = require('../builder/TimelineBuilder');
|
||||
var TweenBuilder = require('../builder/TweenBuilder');
|
||||
var NumberTweenBuilder = require('../builder/NumberTweenBuilder');
|
||||
var TWEEN_CONST = require('../tween/const');
|
||||
|
||||
var TweenManager = new Class({
|
||||
|
@ -78,6 +79,18 @@ var TweenManager = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
// Create a Tween and add it to the active Tween list
|
||||
addCounter: function (config)
|
||||
{
|
||||
var tween = NumberTweenBuilder(this, config);
|
||||
|
||||
this._add.push(tween);
|
||||
|
||||
this._toProcess++;
|
||||
|
||||
return tween;
|
||||
},
|
||||
|
||||
begin: function ()
|
||||
{
|
||||
if (this._toProcess === 0)
|
||||
|
|
Loading…
Reference in a new issue