Skip to content

Commit a19e477

Browse files
committed
The Layer Game Object has been given all of the missing properties and methods from Game Object to make the class shapes identical. This includes the properties parentContainer, tabIndex, input and body. You cannot set any of these properties, they are ignored by the Layer itself. It also includes the methods: setInteractive, disableInteractive and removeInteractive. A Layer cannot be enabled for input or have a physics body. Fix phaserjs#5459
1 parent 234b259 commit a19e477

1 file changed

Lines changed: 135 additions & 0 deletions

File tree

src/gameobjects/layer/Layer.js

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ var Layer = new Class({
152152
*/
153153
this.state = 0;
154154

155+
/**
156+
* A Layer cannot be placed inside a Container.
157+
*
158+
* This property is kept purely so a Layer has the same
159+
* shape as a Game Object.
160+
*
161+
* @name Phaser.GameObjects.Layer#parentContainer
162+
* @type {Phaser.GameObjects.Container}
163+
* @since 3.51.0
164+
*/
165+
this.parentContainer = null;
166+
155167
/**
156168
* The name of this Game Object.
157169
* Empty by default and never populated by Phaser, this is left for developers to use.
@@ -175,6 +187,17 @@ var Layer = new Class({
175187
*/
176188
this.active = true;
177189

190+
/**
191+
* The Tab Index of the Game Object.
192+
* Reserved for future use by plugins and the Input Manager.
193+
*
194+
* @name Phaser.GameObjects.Layer#tabIndex
195+
* @type {number}
196+
* @default -1
197+
* @since 3.51.0
198+
*/
199+
this.tabIndex = -1;
200+
178201
/**
179202
* A Data Manager.
180203
* It allows you to store, query and get key/value paired information specific to this Game Object.
@@ -214,6 +237,28 @@ var Layer = new Class({
214237
*/
215238
this.cameraFilter = 0;
216239

240+
/**
241+
* This property is kept purely so a Layer has the same
242+
* shape as a Game Object. You cannot input enable a Layer.
243+
*
244+
* @name Phaser.GameObjects.Layer#input
245+
* @type {?Phaser.Types.Input.InteractiveObject}
246+
* @default null
247+
* @since 3.51.0
248+
*/
249+
this.input = null;
250+
251+
/**
252+
* This property is kept purely so a Layer has the same
253+
* shape as a Game Object. You cannot give a Layer a physics body.
254+
*
255+
* @name Phaser.GameObjects.Layer#body
256+
* @type {?(Phaser.Physics.Arcade.Body|Phaser.Physics.Arcade.StaticBody|MatterJS.BodyType)}
257+
* @default null
258+
* @since 3.51.0
259+
*/
260+
this.body = null;
261+
217262
/**
218263
* This Game Object will ignore all calls made to its destroy method if this flag is set to `true`.
219264
* This includes calls that may come from a Group, Container or the Scene itself.
@@ -511,6 +556,54 @@ var Layer = new Class({
511556
return this.data.get(key);
512557
},
513558

559+
/**
560+
* A Layer cannot be enabled for input.
561+
*
562+
* This method does nothing and is kept to ensure
563+
* the Layer has the same shape as a Game Object.
564+
*
565+
* @method Phaser.GameObjects.Layer#setInteractive
566+
* @since 3.51.0
567+
*
568+
* @return {this} This GameObject.
569+
*/
570+
setInteractive: function ()
571+
{
572+
return this;
573+
},
574+
575+
/**
576+
* A Layer cannot be enabled for input.
577+
*
578+
* This method does nothing and is kept to ensure
579+
* the Layer has the same shape as a Game Object.
580+
*
581+
* @method Phaser.GameObjects.Layer#disableInteractive
582+
* @since 3.51.0
583+
*
584+
* @return {this} This GameObject.
585+
*/
586+
disableInteractive: function ()
587+
{
588+
return this;
589+
},
590+
591+
/**
592+
* A Layer cannot be enabled for input.
593+
*
594+
* This method does nothing and is kept to ensure
595+
* the Layer has the same shape as a Game Object.
596+
*
597+
* @method Phaser.GameObjects.Layer#removeInteractive
598+
* @since 3.51.0
599+
*
600+
* @return {this} This GameObject.
601+
*/
602+
removeInteractive: function ()
603+
{
604+
return this;
605+
},
606+
514607
/**
515608
* This callback is invoked when this Game Object is added to a Scene.
516609
*
@@ -582,6 +675,48 @@ var Layer = new Class({
582675
return !(this.renderFlags !== 15 || this.list.length === 0 || (this.cameraFilter !== 0 && (this.cameraFilter & camera.id)));
583676
},
584677

678+
/**
679+
* Returns an array containing the display list index of either this Game Object, or if it has one,
680+
* its parent Container. It then iterates up through all of the parent containers until it hits the
681+
* root of the display list (which is index 0 in the returned array).
682+
*
683+
* Used internally by the InputPlugin but also useful if you wish to find out the display depth of
684+
* this Game Object and all of its ancestors.
685+
*
686+
* @method Phaser.GameObjects.Layer#getIndexList
687+
* @since 3.51.0
688+
*
689+
* @return {number[]} An array of display list position indexes.
690+
*/
691+
getIndexList: function ()
692+
{
693+
// eslint-disable-next-line consistent-this
694+
var child = this;
695+
var parent = this.parentContainer;
696+
697+
var indexes = [];
698+
699+
while (parent)
700+
{
701+
indexes.unshift(parent.getIndex(child));
702+
703+
child = parent;
704+
705+
if (!parent.parentContainer)
706+
{
707+
break;
708+
}
709+
else
710+
{
711+
parent = parent.parentContainer;
712+
}
713+
}
714+
715+
indexes.unshift(this.displayList.getIndex(child));
716+
717+
return indexes;
718+
},
719+
585720
/**
586721
* Internal method called from `List.addCallback`.
587722
*

0 commit comments

Comments
 (0)