Skip to content

Commit 06b2a2c

Browse files
committed
Added Tween.generateData back in, now all the Particles and Tween examples work properly.
1 parent af81672 commit 06b2a2c

3 files changed

Lines changed: 98 additions & 88 deletions

File tree

src/gameobjects/GameObjectCreator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Phaser.GameObjectCreator.prototype = {
7070
*/
7171
tween: function (obj) {
7272

73-
return new Phaser.Tween(obj, this.game);
73+
return new Phaser.Tween(obj, this.game, this.game.tweens);
7474

7575
},
7676

src/tween/Tween.js

Lines changed: 19 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -796,125 +796,57 @@ Phaser.Tween.prototype = {
796796
}
797797
}
798798

799-
}
799+
},
800800

801801
/**
802802
* This will generate an array populated with the tweened object values from start to end.
803-
* It works by running the tween simulation at the given frame rate based on the values set-up in Tween.to and similar functions.
804-
* It ignores delay and repeat counts and any chained tweens. Just one play through of tween data is returned, including yoyo if set.
803+
* It works by running the tween simulation at the given frame rate based on the values set-up in Tween.to and Tween.from.
804+
* It ignores delay and repeat counts and any chained tweens, but does include child tweens.
805+
* Just one play through of the tween data is returned, including yoyo if set.
805806
*
806807
* @method Phaser.Tween#generateData
807808
* @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.
808809
* @param {array} [data] - If given the generated data will be appended to this array, otherwise a new array will be returned.
809810
* @return {array} An array of tweened values.
811+
*/
810812
generateData: function (frameRate, data) {
811813

812814
if (this.game === null || this.target === null)
813815
{
814816
return null;
815817
}
816818

817-
this.startTime = 0;
819+
if (typeof data === 'undefined') { data = []; }
818820

819-
for (var property in this._valuesEnd)
820-
{
821-
// Check if an Array was provided as property value
822-
if (Array.isArray(this._valuesEnd[property]))
823-
{
824-
if (this._valuesEnd[property].length === 0)
825-
{
826-
continue;
827-
}
828-
829-
// create a local copy of the Array with the start value at the front
830-
this._valuesEnd[property] = [this.target[property]].concat(this._valuesEnd[property]);
831-
}
832-
833-
this._valuesStart[property] = this.target[property];
834-
835-
if (!Array.isArray(this._valuesStart[property]))
836-
{
837-
this._valuesStart[property] *= 1.0; // Ensures we're using numbers, not strings
838-
}
839-
840-
this._valuesStartRepeat[property] = this._valuesStart[property] || 0;
841-
}
842-
843-
// Simulate the tween. We will run for frameRate * (this.duration / 1000) (ms)
844-
var time = 0;
845-
var total = Math.floor(frameRate * (this.duration / 1000));
846-
var tick = this.duration / total;
847-
848-
var output = [];
849-
850-
while (total--)
821+
// Populate the tween data
822+
for (var i = 0; i < this.timeline.length; i++)
851823
{
852-
var property;
853-
854-
var percent = (time - this.startTime) / this.duration;
855-
percent = percent > 1 ? 1 : percent;
856-
857-
var value = this.easingFunction(percent);
858-
var blob = {};
859-
860-
for (property in this._valuesEnd)
824+
// Build our master property list with the starting values
825+
for (var property in this.timeline[i].vEnd)
861826
{
862-
var start = this._valuesStart[property] || 0;
863-
var end = this._valuesEnd[property];
827+
this.properties[property] = this.target[property] || 0;
864828

865-
if (end instanceof Array)
866-
{
867-
blob[property] = this.interpolationFunction(end, value);
868-
}
869-
else
829+
if (!Array.isArray(this.properties[property]))
870830
{
871-
if (typeof end === 'string')
872-
{
873-
// Parses relative end values with start as base (e.g.: +10, -3)
874-
end = start + parseFloat(end, 10);
875-
}
876-
else if (typeof end === 'number')
877-
{
878-
// Protect against non numeric properties.
879-
blob[property] = start + (end - start) * value;
880-
}
831+
// Ensures we're using numbers, not strings
832+
this.properties[property] *= 1.0;
881833
}
882834
}
883-
884-
output.push(blob);
885-
886-
time += tick;
887835
}
888836

889-
var blob = {};
890-
891-
for (property in this._valuesEnd)
837+
for (var i = 0; i < this.timeline.length; i++)
892838
{
893-
blob[property] = this._valuesEnd[property];
839+
this.timeline[i].loadValues();
894840
}
895841

896-
output.push(blob);
897-
898-
if (this.yoyo)
842+
for (var i = 0; i < this.timeline.length; i++)
899843
{
900-
var reversed = output.slice();
901-
reversed.reverse();
902-
output = output.concat(reversed);
844+
data = data.concat(this.timeline[i].generateData(frameRate));
903845
}
904846

905-
if (typeof data !== 'undefined')
906-
{
907-
data = data.concat(output);
908-
909-
return data;
910-
}
911-
else
912-
{
913-
return output;
914-
}
847+
return data;
915848

916849
}
917-
*/
918850

919851
};
920852

src/tween/TweenData.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,84 @@ Phaser.TweenData.prototype = {
369369

370370
},
371371

372+
/**
373+
* This will generate an array populated with the tweened object values from start to end.
374+
* It works by running the tween simulation at the given frame rate based on the values set-up in Tween.to and Tween.from.
375+
* Just one play through of the tween data is returned, including yoyo if set.
376+
*
377+
* @method Phaser.TweenData#generateData
378+
* @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.
379+
* @return {array} An array of tweened values.
380+
*/
381+
generateData: function (frameRate) {
382+
383+
if (this.parent.reverse)
384+
{
385+
this.dt = this.duration;
386+
}
387+
else
388+
{
389+
this.dt = 0;
390+
}
391+
392+
var data = [];
393+
var complete = false;
394+
var fps = (1 / frameRate) * 1000;
395+
396+
do
397+
{
398+
if (this.parent.reverse)
399+
{
400+
this.dt -= fps;
401+
this.dt = Math.max(this.dt, 0);
402+
}
403+
else
404+
{
405+
this.dt += fps;
406+
this.dt = Math.min(this.dt, this.duration);
407+
}
408+
409+
this.percent = this.dt / this.duration;
410+
411+
this.value = this.easingFunction(this.percent);
412+
413+
var blob = {};
414+
415+
for (var property in this.vEnd)
416+
{
417+
var start = this.vStart[property];
418+
var end = this.vEnd[property];
419+
420+
if (Array.isArray(end))
421+
{
422+
blob[property] = this.interpolationFunction(end, this.value);
423+
}
424+
else
425+
{
426+
blob[property] = start + ((end - start) * this.value);
427+
}
428+
}
429+
430+
data.push(blob);
431+
432+
if ((!this.parent.reverse && this.percent === 1) || (this.parent.reverse && this.percent === 0))
433+
{
434+
complete = true;
435+
}
436+
437+
} while (!complete)
438+
439+
if (this.yoyo)
440+
{
441+
var reversed = data.slice();
442+
reversed.reverse();
443+
data = data.concat(reversed);
444+
}
445+
446+
return data;
447+
448+
},
449+
372450
/**
373451
* Checks if this Tween is meant to repeat or yoyo and handles doing so.
374452
*

0 commit comments

Comments
 (0)