Tween.generateData(frameRate) allows you to generate tween data into an array, which can then be used however you wish (see new examples)

Added new Retro Font examples.
This commit is contained in:
photonstorm
2014-03-03 22:43:35 +00:00
parent 7183322259
commit 67ad898294
15 changed files with 541 additions and 25 deletions
+24 -2
View File
@@ -372,11 +372,11 @@ Phaser.Group.prototype.bringToTop = function (child) {
/**
* Sends the given child to the bottom of this Group so it renders below all other children.
*
* @method Phaser.Group#sendToBottom
* @method Phaser.Group#sendToBack
* @param {*} child - The child to send to the bottom of this Group.
* @return {*} The child that was moved.
*/
Phaser.Group.prototype.sendToBottom = function (child) {
Phaser.Group.prototype.sendToBack = function (child) {
if (child.parent === this && this.getIndex(child) > 0)
{
@@ -436,6 +436,28 @@ Phaser.Group.prototype.moveDown = function (child) {
}
/**
* Positions the child found at the given index within this Group to the given x and y coordinates.
*
* @method Phaser.Group#xy
* @param {number} index - The index of the child in the Group to set the position of.
* @param {number} x - The new x position of the child.
* @param {number} y - The new y position of the child.
*/
Phaser.Group.prototype.xy = function (index, x, y) {
if (index < 0 || index > this.children.length)
{
return -1;
}
else
{
this.getChildAt(index).x = x;
this.getChildAt(index).y = y;
}
}
/**
* Get the index position of the given child in this Group.
*
+2 -2
View File
@@ -66,11 +66,11 @@ Phaser.GameObjectCreator.prototype = {
*
* @method Phaser.GameObjectCreator#tween
* @param {object} obj - Object the tween will be run on.
* @return {Phaser.Tween} Description.
* @return {Phaser.Tween} The Tween object.
*/
tween: function (obj) {
return this.game.tweens.create(obj);
return new Phaser.Tween(obj, this.game);
},
+100
View File
@@ -303,6 +303,106 @@ 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.
*
* @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.
* @return {array} An array of tweened values.
*/
generateData: function (frameRate) {
if (this.game === null || this._object === null)
{
return null;
}
this._startTime = 0;
for (var property in this._valuesEnd)
{
// Check if an Array was provided as property value
if (Array.isArray(this._valuesEnd[property]))
{
if (this._valuesEnd[property].length === 0)
{
continue;
}
// create a local copy of the Array with the start value at the front
this._valuesEnd[property] = [this._object[property]].concat(this._valuesEnd[property]);
}
this._valuesStart[property] = this._object[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 = frameRate * (this._duration / 1000);
var tick = this._duration / total;
var output = [];
while (total--)
{
var property;
var elapsed = (time - this._startTime) / this._duration;
elapsed = elapsed > 1 ? 1 : elapsed;
var value = this._easingFunction(elapsed);
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
{
// Parses relative end values with start as base (e.g.: +10, -3)
if (typeof(end) === 'string')
{
end = start + parseFloat(end, 10);
}
// protect against non numeric properties.
if (typeof(end) === 'number')
{
blob[property] = start + ( end - start ) * value;
}
}
}
output.push(blob);
time += tick;
}
if (this._yoyo)
{
var reversed = output.slice();
reversed.reverse();
output = output.concat(reversed);
}
return output;
},
/**
* Stops the tween if running and removes it from the TweenManager. If there are any onComplete callbacks or events they are not dispatched.
*