Skip to content

Layer manager


A dictionary to store Layer game objects.

  • Author: Rex
  • Container of game objects


Sample code

Install plugin

Load minify file

  • Load plugin (minify file) in preload stage
    scene.load.plugin('rexlayermanagerplugin', '', true);
  • Add layer manager
    var layerManager = scene.plugins.get('rexlayermanagerplugin').add(scene, config);

Import plugin

  • Install rex plugins from npm
    npm i phaser3-rex-plugins
  • Install plugin in configuration of game
    import LayerManagerPlugin from 'phaser3-rex-plugins/plugins/layermanager-plugin.js';
    var config = {
        // ...
        plugins: {
            global: [{
                key: 'rexLayerManager',
                plugin: LayerManagerPlugin,
                start: true
            // ...
        // ...
    var game = new Phaser.Game(config);
  • Add layer manager
    var layerManager = scene.plugins.get('rexLayerManager').add(scene, config);

Import class

  • Install rex plugins from npm
    npm i phaser3-rex-plugins
  • Import class
    import LayerManager from 'phaser3-rex-plugins/plugins/layermanager.js';
  • Add move-to behavior
    var layerManager = new LayerManager(scene, config);

Create instance

var layerManager = scene.plugins.get('rexLayerManager').add(scene, {
    // layers: ['layer0', 'layer1', ...]


var layerManager = scene.plugins.get('rexLayerManager').add(scene, 
    ['layer0', 'layer1', ...]
  • layers : Add layers by name string array.



Also destroy all layers in this layer manager.

Add layer

// layerManager.add(name, depth);

Add game object to layer

layerManager.addToLayer(name, gameObject);
  • name : Name of layer
  • gameObject : Any kind of game object, include containerLite and related game objects.


Print a warn message if specific layer is not existed.

Get layer

  • Get layer by name
    var layer = layerManager.getLayer(name);
  • Get all layers in this layer manager
    var layers = layerManager.getLayers();
    // var out = layerManager.getLayers(out);

Has layer

var hasLayer = layerManager.has(name);
// var hasLayer = layerManager.exists(name);

Clear layer

  • Destroy all children at layer
  • Move all children from layer to scene's display list
    layerManager.clearLayer(name, false);