Skip to content

Commit 671c92e

Browse files
committed
Added addedToScene and removedFromScene methods
* `GameObject.addedToScene` is a new method that custom Game Objects can use to perform additional set-up when a Game Object is added to a Scene. For example, Sprite uses this to add itself to the Update List. * `GameObject.removedFromScene` is a new method that custom Game Objects can use to perform additional tear-down when a Game Object is removed from a Scene. For example, Sprite uses this to remove themselves from the Update List. * Game Objects no longer automatically remove themselves from the Update List during `preDestroy`. This should be handled directly in the `removedFromScene` method now.
1 parent bc93416 commit 671c92e

1 file changed

Lines changed: 37 additions & 8 deletions

File tree

src/gameobjects/GameObject.js

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ var GameObject = new Class({
5858

5959
/**
6060
* The current state of this Game Object.
61-
*
61+
*
6262
* Phaser itself will never modify this value, although plugins may do so.
63-
*
63+
*
6464
* Use this property to track the state of a Game Object during its lifetime. For example, it could change from
6565
* a state of 'moving', to 'attacking', to 'dead'. The state value should be an integer (ideally mapped to a constant
6666
* in your game code), or a string. These are recommended to keep it light and simple, with fast comparisons.
@@ -230,9 +230,9 @@ var GameObject = new Class({
230230

231231
/**
232232
* Sets the current state of this Game Object.
233-
*
233+
*
234234
* Phaser itself will never modify the State of a Game Object, although plugins may do so.
235-
*
235+
*
236236
* For example, a Game Object could change from a state of 'moving', to 'attacking', to 'dead'.
237237
* The state value should typically be an integer (ideally mapped to a constant
238238
* in your game code), but could also be a string. It is recommended to keep it light and simple.
@@ -337,7 +337,7 @@ var GameObject = new Class({
337337
* before setting the value.
338338
*
339339
* If the key doesn't already exist in the Data Manager then it is created.
340-
*
340+
*
341341
* When the value is first set, a `setdata` event is emitted from this Game Object.
342342
*
343343
* @method Phaser.GameObjects.GameObject#incData
@@ -367,7 +367,7 @@ var GameObject = new Class({
367367
* before setting the value.
368368
*
369369
* If the key doesn't already exist in the Data Manager then it is created.
370-
*
370+
*
371371
* When the value is first set, a `setdata` event is emitted from this Game Object.
372372
*
373373
* @method Phaser.GameObjects.GameObject#toggleData
@@ -505,7 +505,7 @@ var GameObject = new Class({
505505
* If you wish to only temporarily stop an object from receiving input then use
506506
* `disableInteractive` instead, as that toggles the interactive state, where-as
507507
* this erases it completely.
508-
*
508+
*
509509
* If you wish to resize a hit area, don't remove and then set it as being
510510
* interactive. Instead, access the hitarea object directly and resize the shape
511511
* being used. I.e.: `sprite.input.hitArea.setSize(width, height)` (assuming the
@@ -525,6 +525,36 @@ var GameObject = new Class({
525525
return this;
526526
},
527527

528+
/**
529+
* This callback is invoked when this Game Object is added to a Scene.
530+
*
531+
* Can be overriden by custom Game Objects, but be aware of some Game Objects that
532+
* will use this, such as Sprites, to add themselves into the Update List.
533+
*
534+
* You can also listen for the `ADDED_TO_SCENE` event from this Game Object.
535+
*
536+
* @method Phaser.GameObjects.GameObject#addedToScene
537+
* @since 3.50.0
538+
*/
539+
addedToScene: function ()
540+
{
541+
},
542+
543+
/**
544+
* This callback is invoked when this Game Object is removed from a Scene.
545+
*
546+
* Can be overriden by custom Game Objects, but be aware of some Game Objects that
547+
* will use this, such as Sprites, to removed themselves from the Update List.
548+
*
549+
* You can also listen for the `REMOVED_FROM_SCENE` event from this Game Object.
550+
*
551+
* @method Phaser.GameObjects.GameObject#removedFromScene
552+
* @since 3.50.0
553+
*/
554+
removedFromScene: function ()
555+
{
556+
},
557+
528558
/**
529559
* To be overridden by custom GameObjects. Allows base objects to be used in a Pool.
530560
*
@@ -651,7 +681,6 @@ var GameObject = new Class({
651681
if (!fromScene)
652682
{
653683
sys.displayList.remove(this);
654-
sys.updateList.remove(this);
655684
}
656685

657686
if (this.input)

0 commit comments

Comments
 (0)