Layer
A Layer Game Object.
A Layer is a special type of Game Object that acts as a Display List. You can add any type of Game Object to a Layer, just as you would to a Scene. Layers can be used to visually group together 'layers' of Game Objects:
const spaceman = this.add.sprite(150, 300, 'spaceman');
const bunny = this.add.sprite(400, 300, 'bunny');
const elephant = this.add.sprite(650, 300, 'elephant');
const layer = this.add.layer();
layer.add([ spaceman, bunny, elephant ]);
The 3 sprites in the example above will now be managed by the Layer they were added to. Therefore, if you then set layer.setVisible(false) they would all vanish from the display.
You can also control the depth of the Game Objects within the Layer. For example, calling the setDepth method of a child of a Layer will allow you to adjust the depth of that child within the Layer itself, rather than the whole Scene. The Layer, too, can have its depth set as well.
The Layer class also offers many different methods for manipulating the list, such as the methods moveUp, moveDown, sendToBack, bringToTop and so on. These allow you to change the display list position of the Layers children, causing it to adjust the order in which they are rendered. Using setDepth on a child allows you to override this.
Layers have no position or size within the Scene. This means you cannot enable a Layer for physics or input, or change the position, rotation or scale of a Layer. They also have no scroll factor, texture, tint, origin, crop or bounds.
If you need those kind of features then you should use a Container instead. Containers can be added to Layers, but Layers cannot be added to Containers.
However, you can set the Alpha, Blend Mode, Depth, Mask and Visible state of a Layer. These settings will impact all children being rendered by the Layer.
Layers should always be the topmost elements of any scene hierarchy. They can be children of layers, but not of anything else.
Until Phaser version 4.1.0, Layer was not a true GameObject. It is now a true GameObject.
Constructor
new Layer(scene, [children])
Parameters
| name | type | optional | description |
|---|---|---|---|
| scene | Phaser.Scene | No | The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. |
| children | Array.<Phaser.GameObjects.GameObject> | Yes | An optional array of Game Objects to add to this Layer. |
Scope: static
Extends
Phaser.GameObjects.GameObject
Phaser.GameObjects.Components.AlphaSingle
Phaser.GameObjects.Components.BlendMode
Phaser.GameObjects.Components.Depth
Phaser.GameObjects.Components.Mask
Phaser.GameObjects.Components.Visible
Source: src/gameobjects/layer/Layer.js#L18
Since: 3.50.0
Inherited Members
From Phaser.GameObjects.Components.AlphaSingle:
From Phaser.GameObjects.Components.BlendMode:
From Phaser.GameObjects.Components.Depth:
From Phaser.GameObjects.Components.Filters:
- filterCamera
- filters
- filtersAutoFocus
- filtersFocusContext
- filtersForceComposite
- maxFilterSize
- renderFilters
From Phaser.GameObjects.Components.Mask:
From Phaser.GameObjects.Components.Visible:
From Phaser.GameObjects.GameObject:
- active
- body
- cameraFilter
- data
- displayList
- ignoreDestroy
- input
- isDestroyed
- name
- parentContainer
- renderFlags
- state
- tabIndex
- type
- vertexRoundMode
Public Members
_sortKey
_sortKey: string
Description:
The property key to sort by.
Source: src/gameobjects/layer/Layer.js#L512
Since: 3.4.0
addCallback
addCallback: function
Description:
A callback that is invoked every time a child is added to this list.
Source: src/gameobjects/layer/Layer.js#L496
Since: 3.4.0
events
events: Phaser.Events.EventEmitter
Description:
A reference to the Scene Event Emitter.
Source: src/gameobjects/layer/Layer.js#L125
Since: 3.50.0
first
first: Phaser.GameObjects.GameObject
Description:
The first item in the List or null for an empty List.
Source: src/gameobjects/layer/Layer.js#L875
Since: 3.0.0
last
last: Phaser.GameObjects.GameObject
Description:
The last item in the List, or null for an empty List.
Source: src/gameobjects/layer/Layer.js#L884
Since: 3.0.0
length
length: number
Description:
The number of items inside the List.
Source: src/gameobjects/layer/Layer.js#L866
Since: 3.0.0
list
list: Array.<Phaser.GameObjects.GameObject>
Description:
The objects that belong to this collection.
Source: src/gameobjects/layer/Layer.js#L476
Since: 3.0.0
next
next: Phaser.GameObjects.GameObject
Description:
The next item in the List, or null if the entire List has been traversed.
This property can be read successively after reading #first or manually setting the #position to iterate the List.
Source: src/gameobjects/layer/Layer.js#L893
Since: 3.0.0
parent
parent: *
Description:
The parent of this list.
Source: src/gameobjects/layer/Layer.js#L468
Since: 3.0.0
position
position: number
Description:
The index of the current element.
This is used internally when iterating through the list with the #first, #last, #next, and #previous properties.
Source: src/gameobjects/layer/Layer.js#L485
Since: 3.0.0
previous
previous: Phaser.GameObjects.GameObject
Description:
The previous item in the List, or null if the entire List has been traversed.
This property can be read successively after reading #last or manually setting the #position to iterate the List backwards.
Source: src/gameobjects/layer/Layer.js#L904
Since: 3.0.0
removeCallback
removeCallback: function
Description:
A callback that is invoked every time a child is removed from this list.
Source: src/gameobjects/layer/Layer.js#L504
Since: 3.4.0
scene
scene: Phaser.Scene
Description:
A reference to the Scene to which this Game Object belongs.
Game Objects can only belong to one Scene.
You should consider this property as being read-only. You cannot move a Game Object to another Scene by simply changing it.
Overrides: Phaser.GameObjects.GameObject#scene
Source: src/gameobjects/layer/Layer.js#L102
Since: 3.50.0
sortChildrenFlag
sortChildrenFlag: boolean
Description:
The flag that determines whether Game Objects should be sorted when depthSort() is called.
Source: src/gameobjects/layer/Layer.js#L134
Since: 3.50.0
systems
systems: Phaser.Scenes.Systems
Description:
A reference to the Scene Systems.
Source: src/gameobjects/layer/Layer.js#L116
Since: 3.50.0
Inherited Methods
From Phaser.GameObjects.Components.AlphaSingle:
From Phaser.GameObjects.Components.BlendMode:
From Phaser.GameObjects.Components.Depth:
From Phaser.GameObjects.Components.Filters:
- enableFilters
- focusFilters
- focusFiltersOnCamera
- focusFiltersOverride
- renderWebGLFilters
- setFiltersAutoFocus
- setFiltersFocusContext
- setFiltersForceComposite
- setFilterSize
- setRenderFilters
- willRenderFilters
From Phaser.GameObjects.Components.Mask:
From Phaser.GameObjects.Components.RenderSteps:
From Phaser.GameObjects.Components.Visible:
From Phaser.GameObjects.GameObject:
- addedToScene
- addToDisplayList
- addToUpdateList
- getData
- getDisplayList
- getIndexList
- incData
- removedFromScene
- removeFromDisplayList
- removeFromUpdateList
- setActive
- setData
- setDataEnabled
- setName
- setState
- setVertexRoundMode
- toggleData
- toJSON
- update
- willRoundVertices
Public Methods
add
<instance> add(child, [skipCallback])
Description:
Adds the given item to the end of the list. Each item must be unique.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| child | Phaser.GameObjects.GameObject | Array.<Phaser.GameObjects.GameObject> | No | The item, or array of items, to add to the list. | |
| skipCallback | boolean | Yes | false | Skip calling the List.addCallback if this child is added successfully. |
Returns: * - The list's underlying array.
Source: src/gameobjects/layer/Layer.js#L520
Since: 3.0.0
addAt
<instance> addAt(child, [index], [skipCallback])
Description:
Adds an item to list, starting at a specified index. Each item must be unique within the list.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| child | Phaser.GameObjects.GameObject | Array.<Phaser.GameObjects.GameObject> | No | The item, or array of items, to add to the list. | |
| index | number | Yes | 0 | The index in the list at which the element(s) will be inserted. |
| skipCallback | boolean | Yes | false | Skip calling the List.addCallback if this child is added successfully. |
Returns: Array.<Phaser.GameObjects.GameObject> - The List's underlying array.
Source: src/gameobjects/layer/Layer.js#L532
Since: 3.0.0
addListener
<instance> addListener(event, fn, [context])
Description:
Add a listener for a given event.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| event | string | symbol | No | The event name. | |
| fn | function | No | The listener function. | |
| context | * | Yes | "this" | The context to invoke the listener with. |
Overrides: Phaser.GameObjects.GameObject#addListener
Returns: Phaser.GameObjects.Layer - This Layer instance.
Source: src/gameobjects/layer/Layer.js#L399
Since: 3.50.0
bringToTop
<instance> bringToTop(child)
Description:
Brings the given child to the top of this List.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| child | Phaser.GameObjects.GameObject | No | The item to bring to the top of the List. |
Returns: Phaser.GameObjects.GameObject - The item which was moved.
Source: src/gameobjects/layer/Layer.js#L751
Since: 3.0.0
count
<instance> count(property, value)
Description:
Returns the total number of items in the List which have a property matching the given value.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| property | string | No | The property to test on each item. |
| value | Phaser.GameObjects.GameObject | No | The value to test the property against. |
Returns: number - The total number of matching elements.
Source: src/gameobjects/layer/Layer.js#L645
Since: 3.0.0
depthSort
<instance> depthSort()
Description:
Immediately sorts the display list if the flag is set.
Source: src/gameobjects/layer/Layer.js#L296
Since: 3.50.0
destroy
<instance> destroy([fromScene])
Description:
Destroys this Layer removing it from the Display List and Update List and severing all ties to parent resources.
Also destroys all children of this Layer. If you do not wish for the children to be destroyed, you should move them from this Layer first.
Use this to remove this Layer from your game if you don't ever plan to use it again. As long as no reference to it exists within your own code it should become free for garbage collection by the browser.
If you just want to temporarily disable an object then look at using the Game Object Pool instead of destroying it, as destroyed objects cannot be resurrected.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| fromScene | boolean | Yes | false | True if this Game Object is being destroyed by the Scene, false if not. |
Overrides: Phaser.GameObjects.GameObject#destroy
Fires: Phaser.GameObjects.Events#event:DESTROY
Source: src/gameobjects/layer/Layer.js#L915
Since: 3.50.0
disableInteractive
<instance> disableInteractive()
Description:
A Layer cannot be enabled for input.
This method does nothing and is kept to ensure the Layer has the same shape as a Game Object.
Overrides: Phaser.GameObjects.GameObject#disableInteractive
Returns: Phaser.GameObjects.Layer - This GameObject.
Source: src/gameobjects/layer/Layer.js#L183
Since: 3.51.0
each
<instance> each(callback, [context], [args])
Description:
Passes all children to the given callback.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| callback | EachListCallback.<Phaser.GameObjects.GameObject> | No | The function to call. |
| context | any | Yes | Value to use as this when executing callback. |
| args | any | Yes | Additional arguments that will be passed to the callback, after the child. |
Source: src/gameobjects/layer/Layer.js#L848
Since: 3.0.0
emit
<instance> emit(event, [args])
Description:
Calls each of the listeners registered for a given event.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| event | string | symbol | No | The event name. |
| args | * | Yes | Additional arguments that will be passed to the event handler. |
Overrides: Phaser.GameObjects.GameObject#emit
Returns: boolean - true if the event had listeners, else false.
Source: src/gameobjects/layer/Layer.js#L374
Since: 3.50.0
eventNames
<instance> eventNames()
Description:
Return an array listing the events for which the emitter has registered listeners.
Overrides: Phaser.GameObjects.GameObject#eventNames
Returns: Array.<(string | symbol)> -
Source: src/gameobjects/layer/Layer.js#L343
Since: 3.50.0
exists
<instance> exists(child)
Description:
Checks if an item exists within the List.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| child | Phaser.GameObjects.GameObject | No | The item to check for the existence of. |
Returns: boolean - true if the item is found in the list, otherwise false.
Source: src/gameobjects/layer/Layer.js#L825
Since: 3.0.0
getAll
<instance> getAll([property], [value], [startIndex], [endIndex])
Description:
Returns all children in this List.
You can optionally specify a matching criteria using the property and value arguments.
For example: getAll('parent') would return only children that have a property called parent.
You can also specify a value to compare the property to:
getAll('visible', true) would return only children that have their visible property set to true.
Optionally you can specify a start and end index. For example if this List had 100 children, and you set startIndex to 0 and endIndex to 50, it would return matches from only the first 50 children in the List.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| property | string | Yes | An optional property to test against the value argument. |
| value | any | Yes | If property is set then Child.property must strictly equal this value to be included in the results. |
| startIndex | number | Yes | The first child index to start the search from. |
| endIndex | number | Yes | The last child index to search up until. |
Returns: Array.<Phaser.GameObjects.GameObject> - All items of the List which match the given criterion, if any.
Source: src/gameobjects/layer/Layer.js#L619
Since: 3.0.0
getAt
<instance> getAt(index)
Description:
Retrieves the item at a given position inside the List.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| index | number | No | The index of the item. |
Returns: Phaser.GameObjects.GameObject, undefined - The retrieved item, or undefined if it's outside the List's bounds.
Source: src/gameobjects/layer/Layer.js#L545
Since: 3.0.0
getByName
<instance> getByName(name)
Description:
Searches for the first instance of a child with its name property matching the given argument. Should more than one child have the same name only the first is returned.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| name | string | No | The name to search for. |
Returns: Phaser.GameObjects.GameObject - The first child with a matching name, or null if none were found.
Source: src/gameobjects/layer/Layer.js#L580
Since: 3.0.0
getChildren
<instance> getChildren()
Description:
Returns a reference to the array which contains all Game Objects in this Layer.
This is a reference, not a copy of it, so be very careful not to mutate it.
Returns: Array.<Phaser.GameObjects.GameObject> - An array of Game Objects within this Layer.
Source: src/gameobjects/layer/Layer.js#L328
Since: 3.50.0
getFirst
<instance> getFirst(property, value, [startIndex], [endIndex])
Description:
Returns the first element in a given part of the List which matches a specific criterion.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| property | string | No | The name of the property to test or a falsey value to have no criterion. | |
| value | Phaser.GameObjects.GameObject | undefined | No | The value to test the property against, or undefined to allow any value and only check for existence. | |
| startIndex | number | Yes | 0 | The position in the List to start the search at. |
| endIndex | number | Yes | The position in the List to optionally stop the search at. It won't be checked. |
Returns: Phaser.GameObjects.GameObject - The first item which matches the given criterion, or null if no such item exists.
Source: src/gameobjects/layer/Layer.js#L605
Since: 3.0.0
getIndex
<instance> getIndex(child)
Description:
Locates an item within the List and returns its index.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| child | Phaser.GameObjects.GameObject | No | The item to locate. |
Returns: number - The index of the item within the List, or -1 if it's not in the List.
Source: src/gameobjects/layer/Layer.js#L556
Since: 3.0.0
getRandom
<instance> getRandom([startIndex], [length])
Description:
Returns a random child from the list.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| startIndex | number | Yes | 0 | Offset from the front of the list (lowest child). |
| length | number | Yes | "(to top)" | Restriction on the number of values you want to randomly select from. |
Returns: Phaser.GameObjects.GameObject - A random child of this List.
Source: src/gameobjects/layer/Layer.js#L593
Since: 3.0.0
listenerCount
<instance> listenerCount(event)
Description:
Return the number of listeners listening to a given event.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| event | string | symbol | No | The event name. |
Overrides: Phaser.GameObjects.GameObject#listenerCount
Returns: number - The number of listeners.
Source: src/gameobjects/layer/Layer.js#L363
Since: 3.50.0
listeners
<instance> listeners(event)
Description:
Return the listeners registered for a given event.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| event | string | symbol | No | The event name. |
Overrides: Phaser.GameObjects.GameObject#listeners
Returns: Array.<function()> - The registered listeners.
Source: src/gameobjects/layer/Layer.js#L352
Since: 3.50.0
moveAbove
<instance> moveAbove(child1, child2)
Description:
Moves an item above another one in the List. If the given item is already above the other, it isn't moved. Above means toward the end of the List.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| child1 | Phaser.GameObjects.GameObject | No | The element to move above base element. |
| child2 | Phaser.GameObjects.GameObject | No | The base element. |
Source: src/gameobjects/layer/Layer.js#L679
Since: 3.55.0
moveBelow
<instance> moveBelow(child1, child2)
Description:
Moves an item below another one in the List. If the given item is already below the other, it isn't moved. Below means toward the start of the List.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| child1 | Phaser.GameObjects.GameObject | No | The element to move below base element. |
| child2 | Phaser.GameObjects.GameObject | No | The base element. |
Source: src/gameobjects/layer/Layer.js#L691
Since: 3.55.0
moveDown
<instance> moveDown(child)
Description:
Moves the given child down one place in this List unless it's already at the bottom.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| child | Phaser.GameObjects.GameObject | No | The item to move down. |
Returns: Phaser.GameObjects.GameObject - The item which was moved.
Source: src/gameobjects/layer/Layer.js#L784
Since: 3.0.0
moveTo
<instance> moveTo(child, index)
Description:
Moves an item in the List to a new position.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| child | Phaser.GameObjects.GameObject | No | The item to move. |
| index | number | No | The new position to move the item to. |
Returns: Phaser.GameObjects.GameObject - The item that was moved.
Source: src/gameobjects/layer/Layer.js#L667
Since: 3.0.0
moveUp
<instance> moveUp(child)
Description:
Moves the given child up one place in this List unless it's already at the top.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| child | Phaser.GameObjects.GameObject | No | The item to move up. |
Returns: Phaser.GameObjects.GameObject - The item which was moved.
Source: src/gameobjects/layer/Layer.js#L773
Since: 3.0.0
off
<instance> off(event, [fn], [context], [once])
Description:
Remove the listeners of a given event.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| event | string | symbol | No | The event name. |
| fn | function | Yes | Only remove the listeners that match this function. |
| context | * | Yes | Only remove the listeners that have this context. |
| once | boolean | Yes | Only remove one-time listeners. |
Overrides: Phaser.GameObjects.GameObject#off
Returns: Phaser.GameObjects.Layer - This Layer instance.
Source: src/gameobjects/layer/Layer.js#L439
Since: 3.50.0
on
<instance> on(event, fn, [context])
Description:
Add a listener for a given event.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| event | string | symbol | No | The event name. | |
| fn | function | No | The listener function. | |
| context | * | Yes | "this" | The context to invoke the listener with. |
Overrides: Phaser.GameObjects.GameObject#on
Returns: Phaser.GameObjects.Layer - This Layer instance.
Source: src/gameobjects/layer/Layer.js#L386
Since: 3.50.0
once
<instance> once(event, fn, [context])
Description:
Add a one-time listener for a given event.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| event | string | symbol | No | The event name. | |
| fn | function | No | The listener function. | |
| context | * | Yes | "this" | The context to invoke the listener with. |
Overrides: Phaser.GameObjects.GameObject#once
Returns: Phaser.GameObjects.Layer - This Layer instance.
Source: src/gameobjects/layer/Layer.js#L412
Since: 3.50.0
queueDepthSort
<instance> queueDepthSort()
Description:
Force a sort of the display list on the next call to depthSort.
Source: src/gameobjects/layer/Layer.js#L285
Since: 3.50.0
remove
<instance> remove(child, [skipCallback])
Description:
Removes one or many items from the List.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| child | Phaser.GameObjects.GameObject | Array.<Phaser.GameObjects.GameObject> | No | The item, or array of items, to remove. | |
| skipCallback | boolean | Yes | false | Skip calling the List.removeCallback. |
Returns: Phaser.GameObjects.GameObject, Array.<Phaser.GameObjects.GameObject> - The item, or array of items, which were successfully removed from the List.
Source: src/gameobjects/layer/Layer.js#L703
Since: 3.0.0
removeAll
<instance> removeAll([skipCallback])
Description:
Removes all the items.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| skipCallback | boolean | Yes | false | Skip calling the List.removeCallback. |
Returns: Phaser.GameObjects.Layer - This List object.
Source: src/gameobjects/layer/Layer.js#L740
Since: 3.0.0
removeAllListeners
<instance> removeAllListeners([event])
Description:
Remove all listeners, or those of the specified event.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| event | string | symbol | Yes | The event name. |
Overrides: Phaser.GameObjects.GameObject#removeAllListeners
Returns: Phaser.GameObjects.Layer - This Layer instance.
Source: src/gameobjects/layer/Layer.js#L453
Since: 3.50.0
removeAt
<instance> removeAt(index, [skipCallback])
Description:
Removes the item at the given position in the List.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| index | number | No | The position to remove the item from. | |
| skipCallback | boolean | Yes | false | Skip calling the List.removeCallback. |
Returns: Phaser.GameObjects.GameObject - The item that was removed.
Source: src/gameobjects/layer/Layer.js#L715
Since: 3.0.0
removeBetween
<instance> removeBetween([startIndex], [endIndex], [skipCallback])
Description:
Removes the items within the given range in the List.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| startIndex | number | Yes | 0 | The index to start removing from. |
| endIndex | number | Yes | The position to stop removing at. The item at this position won't be removed. | |
| skipCallback | boolean | Yes | false | Skip calling the List.removeCallback. |
Returns: Array.<Phaser.GameObjects.GameObject> - An array of the items which were removed.
Source: src/gameobjects/layer/Layer.js#L727
Since: 3.0.0
removeInteractive
<instance> removeInteractive()
Description:
A Layer cannot be enabled for input.
This method does nothing and is kept to ensure the Layer has the same shape as a Game Object.
Overrides: Phaser.GameObjects.GameObject#removeInteractive
Returns: Phaser.GameObjects.Layer - This GameObject.
Source: src/gameobjects/layer/Layer.js#L199
Since: 3.51.0
removeListener
<instance> removeListener(event, [fn], [context], [once])
Description:
Remove the listeners of a given event.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| event | string | symbol | No | The event name. |
| fn | function | Yes | Only remove the listeners that match this function. |
| context | * | Yes | Only remove the listeners that have this context. |
| once | boolean | Yes | Only remove one-time listeners. |
Overrides: Phaser.GameObjects.GameObject#removeListener
Returns: Phaser.GameObjects.Layer - This Layer instance.
Source: src/gameobjects/layer/Layer.js#L425
Since: 3.50.0
replace
<instance> replace(oldChild, newChild)
Description:
Replaces a child of this List with the given newChild. The newChild cannot be a member of this List.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| oldChild | Phaser.GameObjects.GameObject | No | The child in this List that will be replaced. |
| newChild | Phaser.GameObjects.GameObject | No | The child to be inserted into this List. |
Returns: Phaser.GameObjects.GameObject - Returns the oldChild that was replaced within this List.
Source: src/gameobjects/layer/Layer.js#L813
Since: 3.0.0
reverse
<instance> reverse()
Description:
Reverses the order of all children in this List.
Returns: Phaser.GameObjects.Layer - This List object.
Source: src/gameobjects/layer/Layer.js#L795
Since: 3.0.0
sendToBack
<instance> sendToBack(child)
Description:
Sends the given child to the bottom of this List.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| child | Phaser.GameObjects.GameObject | No | The item to send to the back of the list. |
Returns: Phaser.GameObjects.GameObject - The item which was moved.
Source: src/gameobjects/layer/Layer.js#L762
Since: 3.0.0
setAll
<instance> setAll(property, value, [startIndex], [endIndex])
Description:
Sets the property key to the given value on all members of this List.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| property | string | No | The name of the property to set. |
| value | any | No | The value to set the property to. |
| startIndex | number | Yes | The first child index to start the search from. |
| endIndex | number | Yes | The last child index to search up until. |
Source: src/gameobjects/layer/Layer.js#L836
Since: 3.0.0
setInteractive
<instance> setInteractive()
Description:
A Layer cannot be enabled for input.
This method does nothing and is kept to ensure the Layer has the same shape as a Game Object.
Overrides: Phaser.GameObjects.GameObject#setInteractive
Returns: Phaser.GameObjects.Layer - This GameObject.
Source: src/gameobjects/layer/Layer.js#L167
Since: 3.51.0
shuffle
<instance> shuffle()
Description:
Shuffles the items in the list.
Returns: Phaser.GameObjects.Layer - This List object.
Source: src/gameobjects/layer/Layer.js#L804
Since: 3.0.0
shutdown
<instance> shutdown()
Description:
Clears the List and recreates its internal array.
Overrides: Phaser.GameObjects.GameObject#shutdown
Source: src/gameobjects/layer/Layer.js#L859
Since: 3.0.0
sort
<instance> sort(property, [handler])
Description:
Sort the contents of this List so the items are in order based on the given property. For example, sort('alpha') would sort the List contents based on the value of their alpha property.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| property | string | No | The property to lexically sort by. |
| handler | function | Yes | Provide your own custom handler function. Will receive 2 children which it should compare and return a number (negative if the first should come before the second, positive if after, zero if equal). |
Returns: Phaser.GameObjects.Layer - This List object.
Source: src/gameobjects/layer/Layer.js#L567
Since: 3.0.0
sortByDepth
<instance> sortByDepth(childA, childB)
Description:
Compare the depth of two Game Objects.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| childA | Phaser.GameObjects.GameObject | No | The first Game Object. |
| childB | Phaser.GameObjects.GameObject | No | The second Game Object. |
Returns: number - The difference between the depths of each Game Object.
Source: src/gameobjects/layer/Layer.js#L312
Since: 3.50.0
swap
<instance> swap(child1, child2)
Description:
Swaps the positions of two items in the list.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| child1 | Phaser.GameObjects.GameObject | No | The first item to swap. |
| child2 | Phaser.GameObjects.GameObject | No | The second item to swap. |
Source: src/gameobjects/layer/Layer.js#L657
Since: 3.0.0
willRender
<instance> willRender(camera)
Description:
Compares the renderMask with the renderFlags to see if this Game Object will render or not. Also checks the Game Object against the given Cameras exclusion list.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera to check against this Game Object. |
Overrides: Phaser.GameObjects.GameObject#willRender
Returns: boolean - True if the Game Object should be rendered, otherwise false.
Source: src/gameobjects/layer/Layer.js#L215
Since: 3.50.0