Layer

The Phaser.GameObjects.Layer object type allows grouping objects. Unlike the Container objects, a layer cannot be transformed. It doesn’t have position, angle or scale. Its only purpose is to sort the objects for rendering, quickly.

Learn more about Layers in the Phaser docs.

Learn more about working with parent objects in the Scene Editor.

You can create a Layer by dropping a Layer built-in block on the scene, or with the Create Layer with Selection command.

Creating an empty layer.

The code generated by the scene compiler, to create a Layer, is like this:

// create the layer
const layer_1 = this.add.layer();

// create an object and add it to the layer
const someObject = ... ;
layer_1.add(someObject);

Grouping objects in a Layer

You can create a layer with a couple of objects. You can do this by selecting the objects and executing the Create Layer with Selection command. The command is available in the Parent context menu.

When you execute the command, the selected objects are removed from the original parents and added to the new layer. All objects keep the same absolute position. If all objects are children of a common layer, then the new layer will be added to the original parent layer.

Layer properties

The Layer type contains some of the common object properties:

Updated on