Skip to content

Commit 2d08fab

Browse files
committed
When creating a Sprite (via Group.create or directly) with exists = false and a P2 body, the body is not added to the world.
Every Input class now checks to see if it has already been started. If so it doesn't add the listeners again unless they have been nulled.
1 parent 164f3cb commit 2d08fab

15 files changed

Lines changed: 290 additions & 33 deletions

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ Updated
9999
* The StateManager is now responsible for clearing down input, timers, tweens, physics, camera and the World display list.
100100
* Removed the use of Int16Array from all Game Objects, swapped for standard Array. Phaser now runs on Android 2.x again (fix #590)
101101
* When creating a Sprite (via Group.create or directly) with exists = false and a P2 body, the body is not added to the world.
102+
* Every Input class now checks to see if it has already been started. If so it doesn't add the listeners again unless they have been nulled.
102103

103104

104105
New Features

build/custom/p2.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12777,7 +12777,10 @@ Phaser.Physics.P2.Body = function (game, sprite, x, y, mass) {
1277712777
{
1277812778
this.setRectangleFromSprite(sprite);
1277912779

12780-
this.game.physics.p2.addBody(this);
12780+
if (sprite.exists)
12781+
{
12782+
this.game.physics.p2.addBody(this);
12783+
}
1278112784
}
1278212785

1278312786
};

build/custom/p2.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/custom/phaser-no-libs.js

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Phaser - http://www.phaser.io
99
*
10-
* v2.0.1 "Aes Sedai" - Built: Wed Mar 19 2014 12:12:33
10+
* v2.0.1 "Aes Sedai" - Built: Wed Mar 19 2014 13:21:46
1111
*
1212
* By Richard Davey http://www.photonstorm.com @photonstorm
1313
*
@@ -6516,13 +6516,16 @@ Phaser.Group.prototype.set = function (child, key, value, checkAlive, checkVisib
65166516

65176517
/**
65186518
* This function allows you to quickly set the same property across all children of this Group to a new value.
6519+
* This call doesn't descend down children, so if you have a Group inside of this Group, the property will be set on the Group but not its children.
6520+
* If you need that ability please see `Group.setAllChildren`.
6521+
*
65196522
* The operation parameter controls how the new value is assigned to the property, from simple replacement to addition and multiplication.
65206523
*
65216524
* @method Phaser.Group#setAll
65226525
* @param {string} key - The property, as a string, to be set. For example: 'body.velocity.x'
65236526
* @param {*} value - The value that will be set.
6524-
* @param {boolean} [checkAlive=false] - If set then only children with alive=true will be updated.
6525-
* @param {boolean} [checkVisible=false] - If set then only children with visible=true will be updated.
6527+
* @param {boolean} [checkAlive=false] - If set then only children with alive=true will be updated. This includes any Groups that are children.
6528+
* @param {boolean} [checkVisible=false] - If set then only children with visible=true will be updated. This includes any Groups that are children.
65266529
* @param {number} [operation=0] - Controls how the value is assigned. A value of 0 replaces the value with the new one. A value of 1 adds it, 2 subtracts it, 3 multiplies it and 4 divides it.
65276530
*/
65286531
Phaser.Group.prototype.setAll = function (key, value, checkAlive, checkVisible, operation) {
@@ -6544,6 +6547,45 @@ Phaser.Group.prototype.setAll = function (key, value, checkAlive, checkVisible,
65446547

65456548
}
65466549

6550+
/**
6551+
* This function allows you to quickly set the same property across all children of this Group, and any child Groups, to a new value.
6552+
*
6553+
* If this Group contains other Groups then the same property is set across their children as well, iterating down until it reaches the bottom.
6554+
* Unlike with Group.setAll the property is NOT set on child Groups itself.
6555+
*
6556+
* The operation parameter controls how the new value is assigned to the property, from simple replacement to addition and multiplication.
6557+
*
6558+
* @method Phaser.Group#setAllChildren
6559+
* @param {string} key - The property, as a string, to be set. For example: 'body.velocity.x'
6560+
* @param {*} value - The value that will be set.
6561+
* @param {boolean} [checkAlive=false] - If set then only children with alive=true will be updated. This includes any Groups that are children.
6562+
* @param {boolean} [checkVisible=false] - If set then only children with visible=true will be updated. This includes any Groups that are children.
6563+
* @param {number} [operation=0] - Controls how the value is assigned. A value of 0 replaces the value with the new one. A value of 1 adds it, 2 subtracts it, 3 multiplies it and 4 divides it.
6564+
*/
6565+
Phaser.Group.prototype.setAllChildren = function (key, value, checkAlive, checkVisible, operation) {
6566+
6567+
if (typeof checkAlive === 'undefined') { checkAlive = false; }
6568+
if (typeof checkVisible === 'undefined') { checkVisible = false; }
6569+
6570+
operation = operation || 0;
6571+
6572+
for (var i = 0, len = this.children.length; i < len; i++)
6573+
{
6574+
if ((!checkAlive || (checkAlive && this.children[i].alive)) && (!checkVisible || (checkVisible && this.children[i].visible)))
6575+
{
6576+
if (this.children[i] instanceof Phaser.Group)
6577+
{
6578+
this.children[i].setAllChildren(key, value, checkAlive, checkVisible, operation);
6579+
}
6580+
else
6581+
{
6582+
this.setProperty(this.children[i], key.split('.'), value, operation);
6583+
}
6584+
}
6585+
}
6586+
6587+
}
6588+
65476589
/**
65486590
* Adds the amount to the given property on all children in this Group.
65496591
* Group.addAll('x', 10) will add 10 to the child.x value.
@@ -10528,6 +10570,12 @@ Phaser.Keyboard.prototype = {
1052810570
*/
1052910571
start: function () {
1053010572

10573+
if (this._onKeyDown !== null)
10574+
{
10575+
// Avoid setting multiple listeners
10576+
return;
10577+
}
10578+
1053110579
var _this = this;
1053210580

1053310581
this._onKeyDown = function (event) {
@@ -11003,14 +11051,20 @@ Phaser.Mouse.prototype = {
1100311051
*/
1100411052
start: function () {
1100511053

11006-
var _this = this;
11007-
1100811054
if (this.game.device.android && this.game.device.chrome === false)
1100911055
{
1101011056
// Android stock browser fires mouse events even if you preventDefault on the touchStart, so ...
1101111057
return;
1101211058
}
1101311059

11060+
if (this._onMouseDown !== null)
11061+
{
11062+
// Avoid setting multiple listeners
11063+
return;
11064+
}
11065+
11066+
var _this = this;
11067+
1101411068
this._onMouseDown = function (event) {
1101511069
return _this.onMouseDown(event);
1101611070
};
@@ -11270,6 +11324,12 @@ Phaser.MSPointer.prototype = {
1127011324
*/
1127111325
start: function () {
1127211326

11327+
if (this._onMSPointerDown !== null)
11328+
{
11329+
// Avoid setting multiple listeners
11330+
return;
11331+
}
11332+
1127311333
var _this = this;
1127411334

1127511335
if (this.game.device.mspointer === true)
@@ -12145,6 +12205,12 @@ Phaser.Touch.prototype = {
1214512205
*/
1214612206
start: function () {
1214712207

12208+
if (this._onTouchStart !== null)
12209+
{
12210+
// Avoid setting multiple listeners
12211+
return;
12212+
}
12213+
1214812214
var _this = this;
1214912215

1215012216
if (this.game.device.touch)
@@ -12557,7 +12623,14 @@ Phaser.Gamepad.prototype = {
1255712623
*/
1255812624
start: function () {
1255912625

12626+
if (this._active)
12627+
{
12628+
// Avoid setting multiple listeners
12629+
return;
12630+
}
12631+
1256012632
this._active = true;
12633+
1256112634
var _this = this;
1256212635

1256312636
this._ongamepadconnected = function(event) {

build/custom/phaser-no-libs.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/custom/phaser-no-physics.js

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Phaser - http://www.phaser.io
99
*
10-
* v2.0.1 "Aes Sedai" - Built: Wed Mar 19 2014 12:12:33
10+
* v2.0.1 "Aes Sedai" - Built: Wed Mar 19 2014 13:21:46
1111
*
1212
* By Richard Davey http://www.photonstorm.com @photonstorm
1313
*
@@ -9604,7 +9604,7 @@ PIXI.RenderTexture.tempMatrix = new PIXI.Matrix();
96049604
*
96059605
* Phaser - http://www.phaser.io
96069606
*
9607-
* v2.0.1 "Aes Sedai" - Built: Wed Mar 19 2014 12:12:33
9607+
* v2.0.1 "Aes Sedai" - Built: Wed Mar 19 2014 13:21:46
96089608
*
96099609
* By Richard Davey http://www.photonstorm.com @photonstorm
96109610
*
@@ -16113,13 +16113,16 @@ Phaser.Group.prototype.set = function (child, key, value, checkAlive, checkVisib
1611316113

1611416114
/**
1611516115
* This function allows you to quickly set the same property across all children of this Group to a new value.
16116+
* This call doesn't descend down children, so if you have a Group inside of this Group, the property will be set on the Group but not its children.
16117+
* If you need that ability please see `Group.setAllChildren`.
16118+
*
1611616119
* The operation parameter controls how the new value is assigned to the property, from simple replacement to addition and multiplication.
1611716120
*
1611816121
* @method Phaser.Group#setAll
1611916122
* @param {string} key - The property, as a string, to be set. For example: 'body.velocity.x'
1612016123
* @param {*} value - The value that will be set.
16121-
* @param {boolean} [checkAlive=false] - If set then only children with alive=true will be updated.
16122-
* @param {boolean} [checkVisible=false] - If set then only children with visible=true will be updated.
16124+
* @param {boolean} [checkAlive=false] - If set then only children with alive=true will be updated. This includes any Groups that are children.
16125+
* @param {boolean} [checkVisible=false] - If set then only children with visible=true will be updated. This includes any Groups that are children.
1612316126
* @param {number} [operation=0] - Controls how the value is assigned. A value of 0 replaces the value with the new one. A value of 1 adds it, 2 subtracts it, 3 multiplies it and 4 divides it.
1612416127
*/
1612516128
Phaser.Group.prototype.setAll = function (key, value, checkAlive, checkVisible, operation) {
@@ -16141,6 +16144,45 @@ Phaser.Group.prototype.setAll = function (key, value, checkAlive, checkVisible,
1614116144

1614216145
}
1614316146

16147+
/**
16148+
* This function allows you to quickly set the same property across all children of this Group, and any child Groups, to a new value.
16149+
*
16150+
* If this Group contains other Groups then the same property is set across their children as well, iterating down until it reaches the bottom.
16151+
* Unlike with Group.setAll the property is NOT set on child Groups itself.
16152+
*
16153+
* The operation parameter controls how the new value is assigned to the property, from simple replacement to addition and multiplication.
16154+
*
16155+
* @method Phaser.Group#setAllChildren
16156+
* @param {string} key - The property, as a string, to be set. For example: 'body.velocity.x'
16157+
* @param {*} value - The value that will be set.
16158+
* @param {boolean} [checkAlive=false] - If set then only children with alive=true will be updated. This includes any Groups that are children.
16159+
* @param {boolean} [checkVisible=false] - If set then only children with visible=true will be updated. This includes any Groups that are children.
16160+
* @param {number} [operation=0] - Controls how the value is assigned. A value of 0 replaces the value with the new one. A value of 1 adds it, 2 subtracts it, 3 multiplies it and 4 divides it.
16161+
*/
16162+
Phaser.Group.prototype.setAllChildren = function (key, value, checkAlive, checkVisible, operation) {
16163+
16164+
if (typeof checkAlive === 'undefined') { checkAlive = false; }
16165+
if (typeof checkVisible === 'undefined') { checkVisible = false; }
16166+
16167+
operation = operation || 0;
16168+
16169+
for (var i = 0, len = this.children.length; i < len; i++)
16170+
{
16171+
if ((!checkAlive || (checkAlive && this.children[i].alive)) && (!checkVisible || (checkVisible && this.children[i].visible)))
16172+
{
16173+
if (this.children[i] instanceof Phaser.Group)
16174+
{
16175+
this.children[i].setAllChildren(key, value, checkAlive, checkVisible, operation);
16176+
}
16177+
else
16178+
{
16179+
this.setProperty(this.children[i], key.split('.'), value, operation);
16180+
}
16181+
}
16182+
}
16183+
16184+
}
16185+
1614416186
/**
1614516187
* Adds the amount to the given property on all children in this Group.
1614616188
* Group.addAll('x', 10) will add 10 to the child.x value.
@@ -20125,6 +20167,12 @@ Phaser.Keyboard.prototype = {
2012520167
*/
2012620168
start: function () {
2012720169

20170+
if (this._onKeyDown !== null)
20171+
{
20172+
// Avoid setting multiple listeners
20173+
return;
20174+
}
20175+
2012820176
var _this = this;
2012920177

2013020178
this._onKeyDown = function (event) {
@@ -20600,14 +20648,20 @@ Phaser.Mouse.prototype = {
2060020648
*/
2060120649
start: function () {
2060220650

20603-
var _this = this;
20604-
2060520651
if (this.game.device.android && this.game.device.chrome === false)
2060620652
{
2060720653
// Android stock browser fires mouse events even if you preventDefault on the touchStart, so ...
2060820654
return;
2060920655
}
2061020656

20657+
if (this._onMouseDown !== null)
20658+
{
20659+
// Avoid setting multiple listeners
20660+
return;
20661+
}
20662+
20663+
var _this = this;
20664+
2061120665
this._onMouseDown = function (event) {
2061220666
return _this.onMouseDown(event);
2061320667
};
@@ -20867,6 +20921,12 @@ Phaser.MSPointer.prototype = {
2086720921
*/
2086820922
start: function () {
2086920923

20924+
if (this._onMSPointerDown !== null)
20925+
{
20926+
// Avoid setting multiple listeners
20927+
return;
20928+
}
20929+
2087020930
var _this = this;
2087120931

2087220932
if (this.game.device.mspointer === true)
@@ -21742,6 +21802,12 @@ Phaser.Touch.prototype = {
2174221802
*/
2174321803
start: function () {
2174421804

21805+
if (this._onTouchStart !== null)
21806+
{
21807+
// Avoid setting multiple listeners
21808+
return;
21809+
}
21810+
2174521811
var _this = this;
2174621812

2174721813
if (this.game.device.touch)
@@ -22154,7 +22220,14 @@ Phaser.Gamepad.prototype = {
2215422220
*/
2215522221
start: function () {
2215622222

22223+
if (this._active)
22224+
{
22225+
// Avoid setting multiple listeners
22226+
return;
22227+
}
22228+
2215722229
this._active = true;
22230+
2215822231
var _this = this;
2215922232

2216022233
this._ongamepadconnected = function(event) {

build/custom/phaser-no-physics.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)