Skip to content

Commit c9939f8

Browse files
committed
Tilemap fix phaserjs#1635
1 parent 1dee5f2 commit c9939f8

3 files changed

Lines changed: 56 additions & 53 deletions

File tree

src/gameobjects/components/Core.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ Phaser.Component.Core.prototype = {
160160
*/
161161
_bounds: null,
162162

163+
/**
164+
* @property {boolean} _exists - Internal cache var.
165+
* @private
166+
*/
167+
_exists: false,
168+
163169
/**
164170
* Override and use this function in your own custom objects to handle any update requirements you may have.
165171
* Remember if this Sprite has any children you should call update on them too.
@@ -199,6 +205,51 @@ Phaser.Component.Core.prototype = {
199205
this.children[i].postUpdate();
200206
}
201207

208+
},
209+
210+
/**
211+
* Sprite.exists controls if the core game loop and physics update this Sprite or not.
212+
* When you set Sprite.exists to false it will remove its Body from the physics world (if it has one) and also set Sprite.visible to false.
213+
* Setting Sprite.exists to true will re-add the Body to the physics world (if it has a body) and set Sprite.visible to true.
214+
*
215+
* @name Phaser.Sprite#exists
216+
* @property {boolean} exists - If the Sprite is processed by the core game update and physics.
217+
*/
218+
exists: {
219+
220+
get: function () {
221+
222+
return this._exists;
223+
224+
},
225+
226+
set: function (value) {
227+
228+
if (value)
229+
{
230+
this._exists = true;
231+
232+
if (this.body && this.body.type === Phaser.Physics.P2JS)
233+
{
234+
this.body.addToWorld();
235+
}
236+
237+
this.visible = true;
238+
}
239+
else
240+
{
241+
this._exists = false;
242+
243+
if (this.body && this.body.type === Phaser.Physics.P2JS)
244+
{
245+
this.body.removeFromWorld();
246+
}
247+
248+
this.visible = false;
249+
}
250+
251+
}
252+
202253
}
203254

204255
};

src/gameobjects/components/PhysicsBody.js

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -56,59 +56,6 @@ Phaser.Component.PhysicsBody.prototype = {
5656
*/
5757
body: null,
5858

59-
/**
60-
* @property {boolean} _exists - Internal cache var.
61-
* @private
62-
*/
63-
_exists: false,
64-
65-
/**
66-
* Sprite.exists controls if the core game loop and physics update this Sprite or not.
67-
* When you set Sprite.exists to false it will remove its Body from the physics world (if it has one) and also set Sprite.visible to false.
68-
* Setting Sprite.exists to true will re-add the Body to the physics world (if it has a body) and set Sprite.visible to true.
69-
*
70-
* @name Phaser.Sprite#exists
71-
* @property {boolean} exists - If the Sprite is processed by the core game update and physics.
72-
*/
73-
exists: {
74-
75-
get: function () {
76-
77-
return this._exists;
78-
79-
},
80-
81-
set: function (value) {
82-
83-
if (value)
84-
{
85-
// exists = true
86-
this._exists = true;
87-
88-
if (this.body && this.body.type === Phaser.Physics.P2JS)
89-
{
90-
this.body.addToWorld();
91-
}
92-
93-
this.visible = true;
94-
}
95-
else
96-
{
97-
// exists = false
98-
this._exists = false;
99-
100-
if (this.body && this.body.type === Phaser.Physics.P2JS)
101-
{
102-
this.body.removeFromWorld();
103-
}
104-
105-
this.visible = false;
106-
107-
}
108-
}
109-
110-
},
111-
11259
/**
11360
* The position of the Sprite on the x axis relative to the local coordinates of the parent.
11461
*

src/tilemap/TilemapLayer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ Phaser.TilemapLayer = function (game, tilemap, index, width, height) {
135135
*/
136136
this.debug = false;
137137

138+
/**
139+
* @property {boolean} exists - Controls if the core game loop and physics update this game object or not.
140+
*/
141+
this.exists = true;
142+
138143
/**
139144
* Settings used for debugging and diagnostics.
140145
*

0 commit comments

Comments
 (0)