mirror of
https://github.com/photonstorm/phaser
synced 2024-11-16 17:58:23 +00:00
Added Tween.generateData back in, now all the Particles and Tween examples work properly.
This commit is contained in:
parent
af8167258e
commit
06b2a2c6a0
3 changed files with 99 additions and 89 deletions
|
@ -70,7 +70,7 @@ Phaser.GameObjectCreator.prototype = {
|
|||
*/
|
||||
tween: function (obj) {
|
||||
|
||||
return new Phaser.Tween(obj, this.game);
|
||||
return new Phaser.Tween(obj, this.game, this.game.tweens);
|
||||
|
||||
},
|
||||
|
||||
|
|
|
@ -796,17 +796,19 @@ Phaser.Tween.prototype = {
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* This will generate an array populated with the tweened object values from start to end.
|
||||
* It works by running the tween simulation at the given frame rate based on the values set-up in Tween.to and similar functions.
|
||||
* It ignores delay and repeat counts and any chained tweens. Just one play through of tween data is returned, including yoyo if set.
|
||||
* It works by running the tween simulation at the given frame rate based on the values set-up in Tween.to and Tween.from.
|
||||
* It ignores delay and repeat counts and any chained tweens, but does include child tweens.
|
||||
* Just one play through of the tween data is returned, including yoyo if set.
|
||||
*
|
||||
* @method Phaser.Tween#generateData
|
||||
* @param {number} [frameRate=60] - The speed in frames per second that the data should be generated at. The higher the value, the larger the array it creates.
|
||||
* @param {array} [data] - If given the generated data will be appended to this array, otherwise a new array will be returned.
|
||||
* @return {array} An array of tweened values.
|
||||
*/
|
||||
generateData: function (frameRate, data) {
|
||||
|
||||
if (this.game === null || this.target === null)
|
||||
|
@ -814,107 +816,37 @@ Phaser.Tween.prototype = {
|
|||
return null;
|
||||
}
|
||||
|
||||
this.startTime = 0;
|
||||
if (typeof data === 'undefined') { data = []; }
|
||||
|
||||
for (var property in this._valuesEnd)
|
||||
// Populate the tween data
|
||||
for (var i = 0; i < this.timeline.length; i++)
|
||||
{
|
||||
// Check if an Array was provided as property value
|
||||
if (Array.isArray(this._valuesEnd[property]))
|
||||
// Build our master property list with the starting values
|
||||
for (var property in this.timeline[i].vEnd)
|
||||
{
|
||||
if (this._valuesEnd[property].length === 0)
|
||||
this.properties[property] = this.target[property] || 0;
|
||||
|
||||
if (!Array.isArray(this.properties[property]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// create a local copy of the Array with the start value at the front
|
||||
this._valuesEnd[property] = [this.target[property]].concat(this._valuesEnd[property]);
|
||||
}
|
||||
|
||||
this._valuesStart[property] = this.target[property];
|
||||
|
||||
if (!Array.isArray(this._valuesStart[property]))
|
||||
{
|
||||
this._valuesStart[property] *= 1.0; // Ensures we're using numbers, not strings
|
||||
}
|
||||
|
||||
this._valuesStartRepeat[property] = this._valuesStart[property] || 0;
|
||||
}
|
||||
|
||||
// Simulate the tween. We will run for frameRate * (this.duration / 1000) (ms)
|
||||
var time = 0;
|
||||
var total = Math.floor(frameRate * (this.duration / 1000));
|
||||
var tick = this.duration / total;
|
||||
|
||||
var output = [];
|
||||
|
||||
while (total--)
|
||||
{
|
||||
var property;
|
||||
|
||||
var percent = (time - this.startTime) / this.duration;
|
||||
percent = percent > 1 ? 1 : percent;
|
||||
|
||||
var value = this.easingFunction(percent);
|
||||
var blob = {};
|
||||
|
||||
for (property in this._valuesEnd)
|
||||
{
|
||||
var start = this._valuesStart[property] || 0;
|
||||
var end = this._valuesEnd[property];
|
||||
|
||||
if (end instanceof Array)
|
||||
{
|
||||
blob[property] = this.interpolationFunction(end, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (typeof end === 'string')
|
||||
{
|
||||
// Parses relative end values with start as base (e.g.: +10, -3)
|
||||
end = start + parseFloat(end, 10);
|
||||
}
|
||||
else if (typeof end === 'number')
|
||||
{
|
||||
// Protect against non numeric properties.
|
||||
blob[property] = start + (end - start) * value;
|
||||
}
|
||||
// Ensures we're using numbers, not strings
|
||||
this.properties[property] *= 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
output.push(blob);
|
||||
|
||||
time += tick;
|
||||
}
|
||||
|
||||
var blob = {};
|
||||
|
||||
for (property in this._valuesEnd)
|
||||
for (var i = 0; i < this.timeline.length; i++)
|
||||
{
|
||||
blob[property] = this._valuesEnd[property];
|
||||
this.timeline[i].loadValues();
|
||||
}
|
||||
|
||||
output.push(blob);
|
||||
|
||||
if (this.yoyo)
|
||||
for (var i = 0; i < this.timeline.length; i++)
|
||||
{
|
||||
var reversed = output.slice();
|
||||
reversed.reverse();
|
||||
output = output.concat(reversed);
|
||||
data = data.concat(this.timeline[i].generateData(frameRate));
|
||||
}
|
||||
|
||||
if (typeof data !== 'undefined')
|
||||
{
|
||||
data = data.concat(output);
|
||||
|
||||
return data;
|
||||
}
|
||||
else
|
||||
{
|
||||
return output;
|
||||
}
|
||||
return data;
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -369,6 +369,84 @@ Phaser.TweenData.prototype = {
|
|||
|
||||
},
|
||||
|
||||
/**
|
||||
* This will generate an array populated with the tweened object values from start to end.
|
||||
* It works by running the tween simulation at the given frame rate based on the values set-up in Tween.to and Tween.from.
|
||||
* Just one play through of the tween data is returned, including yoyo if set.
|
||||
*
|
||||
* @method Phaser.TweenData#generateData
|
||||
* @param {number} [frameRate=60] - The speed in frames per second that the data should be generated at. The higher the value, the larger the array it creates.
|
||||
* @return {array} An array of tweened values.
|
||||
*/
|
||||
generateData: function (frameRate) {
|
||||
|
||||
if (this.parent.reverse)
|
||||
{
|
||||
this.dt = this.duration;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.dt = 0;
|
||||
}
|
||||
|
||||
var data = [];
|
||||
var complete = false;
|
||||
var fps = (1 / frameRate) * 1000;
|
||||
|
||||
do
|
||||
{
|
||||
if (this.parent.reverse)
|
||||
{
|
||||
this.dt -= fps;
|
||||
this.dt = Math.max(this.dt, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.dt += fps;
|
||||
this.dt = Math.min(this.dt, this.duration);
|
||||
}
|
||||
|
||||
this.percent = this.dt / this.duration;
|
||||
|
||||
this.value = this.easingFunction(this.percent);
|
||||
|
||||
var blob = {};
|
||||
|
||||
for (var property in this.vEnd)
|
||||
{
|
||||
var start = this.vStart[property];
|
||||
var end = this.vEnd[property];
|
||||
|
||||
if (Array.isArray(end))
|
||||
{
|
||||
blob[property] = this.interpolationFunction(end, this.value);
|
||||
}
|
||||
else
|
||||
{
|
||||
blob[property] = start + ((end - start) * this.value);
|
||||
}
|
||||
}
|
||||
|
||||
data.push(blob);
|
||||
|
||||
if ((!this.parent.reverse && this.percent === 1) || (this.parent.reverse && this.percent === 0))
|
||||
{
|
||||
complete = true;
|
||||
}
|
||||
|
||||
} while (!complete)
|
||||
|
||||
if (this.yoyo)
|
||||
{
|
||||
var reversed = data.slice();
|
||||
reversed.reverse();
|
||||
data = data.concat(reversed);
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if this Tween is meant to repeat or yoyo and handles doing so.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue