Skip to content

Commit c5fc5e3

Browse files
committed
Fixed various issues in the TweenManager, added length property to Group and improved the build script.
1 parent cf26f68 commit c5fc5e3

8 files changed

Lines changed: 106 additions & 27 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ Version 1.0.5 (In progress)
3939

4040
* Fixed issue in FrameData.getFrameIndexes where the input array was being ignored.
4141
* Added Math.numberArray - Returns an Array containing the numbers from min to max (inclusive), useful for animation frame construction.
42+
* Fixed a horrendously sneaky bug: If a new tween was created in the onComplete callback of a tween about to be deleted, it would get automatically spliced.
43+
* Added a pendingDelete property to Tween to stop tweens that were removed during a callback from causing update errors during the TweenManager loop.
44+
* Added Group.length property.
45+
4246

4347

4448
Version 1.0.4 (September 18th 2013)

build/build.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
<textarea style="width: 800px; height: 800px">
44
<?php
5-
5+
// Get the version number
6+
// VERSION: '1.0.5',
7+
$vf = file_get_contents('../src/Phaser.js');
8+
$version = substr($vf, strpos($vf, 'VERSION: ') + 10, 5);
9+
10+
echo "Building version $version \n\n";
11+
612
$js = file('../examples/js.php');
713
$output = "";
814

@@ -15,16 +21,21 @@
1521
{
1622
$line = str_replace('<script src="', '', $line);
1723
$line = str_replace('"></script>', '', $line);
24+
$filename = substr($line, strrpos($line, '/') + 1);
1825

1926
echo $line . "\n";
27+
// echo $filename . "\n";
2028

2129
// Read the file in
2230
$source = file_get_contents($line);
2331

24-
if ($i == 4)
32+
if ($filename == 'Intro.js')
2533
{
2634
// Built at: {buildDate}
2735
$source = str_replace('{buildDate}', date('r'), $source);
36+
37+
// {version}
38+
$source = str_replace('{version}', $version, $source);
2839
}
2940

3041
$output .= $source . "\n";

build/phaser.js

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Phaser - http://www.phaser.io
33
*
4-
* v1.0.1 - Built at: Wed, 18 Sep 2013 05:29:56 +0000
4+
* v1.0.5 - Built at: Thu, 19 Sep 2013 03:03:05 +0000
55
*
66
* @author Richard Davey http://www.photonstorm.com @photonstorm
77
*
@@ -34,7 +34,7 @@ var PIXI = PIXI || {};
3434
*/
3535
var Phaser = Phaser || {
3636

37-
VERSION: '1.0.4',
37+
VERSION: '1.0.5',
3838
GAMES: [],
3939
AUTO: 0,
4040
CANVAS: 1,
@@ -16769,6 +16769,26 @@ Phaser.Math = {
1676916769
}
1677016770
}
1677116771

16772+
},
16773+
16774+
/**
16775+
* Returns an Array containing the numbers from min to max (inclusive)
16776+
*
16777+
* @param min The minimum value the array starts with
16778+
* @param max The maximum value the array contains
16779+
* @return The array of number values
16780+
*/
16781+
numberArray: function (min, max) {
16782+
16783+
var result = [];
16784+
16785+
for (var i = min; i <= max; i++)
16786+
{
16787+
result.push(i);
16788+
}
16789+
16790+
return result;
16791+
1677216792
},
1677316793

1677416794
/**
@@ -19282,6 +19302,7 @@ Phaser.TweenManager = function (game) {
1928219302

1928319303
this.game = game;
1928419304
this._tweens = [];
19305+
this._add = [];
1928519306

1928619307
this.game.onPause.add(this.pauseAll, this);
1928719308
this.game.onResume.add(this.resumeAll, this);
@@ -19319,7 +19340,7 @@ Phaser.TweenManager.prototype = {
1931919340
*/
1932019341
add: function ( tween ) {
1932119342

19322-
this._tweens.push( tween );
19343+
this._add.push( tween );
1932319344

1932419345
},
1932519346

@@ -19346,7 +19367,7 @@ Phaser.TweenManager.prototype = {
1934619367

1934719368
if ( i !== -1 ) {
1934819369

19349-
this._tweens.splice( i, 1 );
19370+
this._tweens[i].pendingDelete = true;
1935019371

1935119372
}
1935219373

@@ -19359,9 +19380,10 @@ Phaser.TweenManager.prototype = {
1935919380
*/
1936019381
update: function () {
1936119382

19362-
if ( this._tweens.length === 0 ) return false;
19383+
if ( this._tweens.length === 0 && this._add.length === 0 ) return false;
1936319384

19364-
var i = 0, numTweens = this._tweens.length;
19385+
var i = 0;
19386+
var numTweens = this._tweens.length;
1936519387

1936619388
while ( i < numTweens ) {
1936719389

@@ -19379,6 +19401,13 @@ Phaser.TweenManager.prototype = {
1937919401

1938019402
}
1938119403

19404+
// If there are any new tweens to be added, do so now - otherwise they can be spliced out of the array before ever running
19405+
if (this._add.length > 0)
19406+
{
19407+
this._tweens = this._tweens.concat(this._add);
19408+
this._add.length = 0;
19409+
}
19410+
1938219411
return true;
1938319412

1938419413
},
@@ -19444,6 +19473,8 @@ Phaser.Tween = function (object, game) {
1944419473

1944519474
this._pausedTime = 0;
1944619475

19476+
this.pendingDelete = false;
19477+
1944719478
// Set all starting values present on the target object
1944819479
for ( var field in object ) {
1944919480
this._valuesStart[ field ] = parseFloat(object[field], 10);
@@ -19598,21 +19629,21 @@ Phaser.Tween.prototype = {
1959819629

1959919630
},
1960019631

19601-
onStart: function ( callback ) {
19632+
onStartCallback: function ( callback ) {
1960219633

1960319634
this._onStartCallback = callback;
1960419635
return this;
1960519636

1960619637
},
1960719638

19608-
onUpdate: function ( callback ) {
19639+
onUpdateCallback: function ( callback ) {
1960919640

1961019641
this._onUpdateCallback = callback;
1961119642
return this;
1961219643

1961319644
},
1961419645

19615-
onComplete: function ( callback ) {
19646+
onCompleteCallback: function ( callback ) {
1961619647

1961719648
this._onCompleteCallback = callback;
1961819649
return this;
@@ -19630,6 +19661,11 @@ Phaser.Tween.prototype = {
1963019661

1963119662
update: function ( time ) {
1963219663

19664+
if (this.pendingDelete)
19665+
{
19666+
return false;
19667+
}
19668+
1963319669
if (this._paused || time < this._startTime) {
1963419670

1963519671
return true;
@@ -20819,8 +20855,8 @@ Phaser.Animation.prototype = {
2081920855

2082020856
if (frameRate !== null)
2082120857
{
20822-
// this.delay = 1000 / frameRate;
20823-
this.delay = frameRate;
20858+
this.delay = 1000 / frameRate;
20859+
// this.delay = frameRate;
2082420860
}
2082520861

2082620862
if (loop !== null)
@@ -21421,14 +21457,14 @@ Phaser.Animation.FrameData.prototype = {
2142121457
* @param {Array} [output] Optional array. If given the results will be appended to the end of this Array, otherwise a new array is created.
2142221458
* @return {Array} An array of all Frame indexes matching the given names or IDs.
2142321459
*/
21424-
getFrameIndexes: function (input, useNumericIndex, output) {
21460+
getFrameIndexes: function (frames, useNumericIndex, output) {
2142521461

2142621462
if (typeof useNumericIndex === "undefined") { useNumericIndex = true; }
2142721463
if (typeof output === "undefined") { output = []; }
2142821464

2142921465
if (typeof frames === "undefined" || frames.length == 0)
2143021466
{
21431-
// No input array, so we loop through all frames
21467+
// No frames array, so we loop through all frames
2143221468
for (var i = 0, len = this._frames.length; i < len; i++)
2143321469
{
2143421470
output.push(this._frames[i].index);
@@ -21437,16 +21473,16 @@ Phaser.Animation.FrameData.prototype = {
2143721473
else
2143821474
{
2143921475
// Input array given, loop through that instead
21440-
for (var i = 0, len = input.length; i < len; i++)
21476+
for (var i = 0, len = frames.length; i < len; i++)
2144121477
{
21442-
// Does the input array contain names or indexes?
21478+
// Does the frames array contain names or indexes?
2144321479
if (useNumericIndex)
2144421480
{
21445-
output.push(input[i].index);
21481+
output.push(frames[i].index);
2144621482
}
2144721483
else
2144821484
{
21449-
output.push(this.getFrameByName(input[i]).index);
21485+
output.push(this.getFrameByName(frames[i]).index);
2145021486
}
2145121487
}
2145221488
}
@@ -21613,6 +21649,7 @@ Phaser.Animation.Parser = {
2161321649
);
2161421650

2161521651
PIXI.TextureCache[uuid].realSize = frames[i].spriteSourceSize;
21652+
// PIXI.TextureCache[uuid].realSize = frames[i].sourceSize;
2161621653
PIXI.TextureCache[uuid].trim.x = 0;
2161721654
}
2161821655
}
@@ -21682,6 +21719,7 @@ Phaser.Animation.Parser = {
2168221719
);
2168321720

2168421721
PIXI.TextureCache[uuid].realSize = frames[key].spriteSourceSize;
21722+
// PIXI.TextureCache[uuid].realSize = frames[key].sourceSize;
2168521723
PIXI.TextureCache[uuid].trim.x = 0;
2168621724
}
2168721725

src/Intro.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Phaser - http://www.phaser.io
33
*
4-
* v1.0.1 - Built at: {buildDate}
4+
* v{version} - Built at: {buildDate}
55
*
66
* @author Richard Davey http://www.photonstorm.com @photonstorm
77
*

src/animation/Parser.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ Phaser.Animation.Parser = {
139139
);
140140

141141
PIXI.TextureCache[uuid].realSize = frames[i].spriteSourceSize;
142+
// PIXI.TextureCache[uuid].realSize = frames[i].sourceSize;
142143
PIXI.TextureCache[uuid].trim.x = 0;
143144
}
144145
}
@@ -208,6 +209,7 @@ Phaser.Animation.Parser = {
208209
);
209210

210211
PIXI.TextureCache[uuid].realSize = frames[key].spriteSourceSize;
212+
// PIXI.TextureCache[uuid].realSize = frames[key].sourceSize;
211213
PIXI.TextureCache[uuid].trim.x = 0;
212214
}
213215

src/core/Group.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,14 @@ Phaser.Group.prototype = {
832832

833833
};
834834

835+
Object.defineProperty(Phaser.Group.prototype, "length", {
836+
837+
get: function () {
838+
return this._container.children.length;
839+
}
840+
841+
});
842+
835843
Object.defineProperty(Phaser.Group.prototype, "x", {
836844

837845
get: function () {

src/tween/Tween.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Phaser.Tween = function (object, game) {
3636

3737
this._pausedTime = 0;
3838

39+
this.pendingDelete = false;
40+
3941
// Set all starting values present on the target object
4042
for ( var field in object ) {
4143
this._valuesStart[ field ] = parseFloat(object[field], 10);
@@ -190,21 +192,21 @@ Phaser.Tween.prototype = {
190192

191193
},
192194

193-
onStart: function ( callback ) {
195+
onStartCallback: function ( callback ) {
194196

195197
this._onStartCallback = callback;
196198
return this;
197199

198200
},
199201

200-
onUpdate: function ( callback ) {
202+
onUpdateCallback: function ( callback ) {
201203

202204
this._onUpdateCallback = callback;
203205
return this;
204206

205207
},
206208

207-
onComplete: function ( callback ) {
209+
onCompleteCallback: function ( callback ) {
208210

209211
this._onCompleteCallback = callback;
210212
return this;
@@ -222,6 +224,11 @@ Phaser.Tween.prototype = {
222224

223225
update: function ( time ) {
224226

227+
if (this.pendingDelete)
228+
{
229+
return false;
230+
}
231+
225232
if (this._paused || time < this._startTime) {
226233

227234
return true;

src/tween/TweenManager.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Phaser.TweenManager = function (game) {
1313

1414
this.game = game;
1515
this._tweens = [];
16+
this._add = [];
1617

1718
this.game.onPause.add(this.pauseAll, this);
1819
this.game.onResume.add(this.resumeAll, this);
@@ -50,7 +51,7 @@ Phaser.TweenManager.prototype = {
5051
*/
5152
add: function ( tween ) {
5253

53-
this._tweens.push( tween );
54+
this._add.push( tween );
5455

5556
},
5657

@@ -77,7 +78,7 @@ Phaser.TweenManager.prototype = {
7778

7879
if ( i !== -1 ) {
7980

80-
this._tweens.splice( i, 1 );
81+
this._tweens[i].pendingDelete = true;
8182

8283
}
8384

@@ -90,9 +91,10 @@ Phaser.TweenManager.prototype = {
9091
*/
9192
update: function () {
9293

93-
if ( this._tweens.length === 0 ) return false;
94+
if ( this._tweens.length === 0 && this._add.length === 0 ) return false;
9495

95-
var i = 0, numTweens = this._tweens.length;
96+
var i = 0;
97+
var numTweens = this._tweens.length;
9698

9799
while ( i < numTweens ) {
98100

@@ -110,6 +112,13 @@ Phaser.TweenManager.prototype = {
110112

111113
}
112114

115+
// If there are any new tweens to be added, do so now - otherwise they can be spliced out of the array before ever running
116+
if (this._add.length > 0)
117+
{
118+
this._tweens = this._tweens.concat(this._add);
119+
this._add.length = 0;
120+
}
121+
113122
return true;
114123

115124
},

0 commit comments

Comments
 (0)