Jump to content

Bring to top phaser layer data item


zidein
 Share

Recommended Posts

Hello!
I want to use method BringToTop for layer data item. But it doesnt work for me.

I have some layers, and i want to hide my character behind some sprites.

I need something like that: 
BGSMYDj.png

 

But i have got it:
xkVMEIF.png


Here is my code:
 

this.parent.Location.location = this.parent.game.add.tilemap('map');
if (!this.parent.Location.props.images) {
    console.error('Images are empty or undefined read readme.md for information');
    return false;
}
_.each(this.parent.Location.props.images, (layer, index) => {
    this.parent.Location.location.addTilesetImage(layer.name, layer.name);
    this.parent.Location[layer.layer] = this.parent.Location.location.createLayer(layer.layer);
    this.parent.Location[layer.layer].resizeWorld();
    if (_.size(layer.bringToTop)) {
        this.bringToTop(index, layer.bringToTop); // 0, [6,7]
    }
});
bringToTop(index, bringToTopArray) {
    let gid = this.parent.Location.location.tilesets[index].firstgid;
    _.each(bringToTopArray, (itemBring) => {
        _.each(this.parent.Location.location.layers[index].data, (layerData) => {
            _.each(layerData, (layerDataItem) => {
                if ((itemBring + gid) === layerDataItem.index) {
                    let timeAfterLoad = this.parent.game.time.events.add(0, () => {
                        this.parent.game.world.bringToTop(layerDataItem);
                        this.parent.game.time.events.remove(timeAfterLoad);
                    });
                }
            });
        })
    });
}

If you know another ways how i can resolve that problem, let me know please.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...