Jump to content

Multylayers


eltoncezar
 Share

Recommended Posts

Hi,

 

There is an easy way to render multiple layers of a map created in Tiled? I tried this solution, but it's not working for me.

This is my code:

// Phaser version v2.0.2 "Ghealdan" - Built: Fri Mar 28 2014 01:30:50function preload() {    game.load.tilemap('map', 'assets/tilemaps/maps/adv.json', null, Phaser.Tilemap.TILED_JSON);    game.load.image('tiles', 'assets/tilemaps/tiles/adv.png');}var map;var layer = {};function create() {    map = game.add.tilemap('map');    map.addTilesetImage('adv','tiles');    layer[0] = map.createLayer('Tile Layer 1');    layer[0].resizeWorld();    layer[1] = map.createLayer('Tile Layer 2');    layer[1].resizeWorld();}

But it's only rendering the first defined layer... What I am doing wrong??

Link to comment
Share on other sites

your code looks quite ok to me...    are there any error messages?
 
 
thats what i do and it works..
 
preload:
game.load.tilemap('level1map', './assets/tilesets/level1.json', null, Phaser.Tilemap.TILED_JSON);game.load.image('mariotileset', './assets/tilesets/mariotileset.png');

create:

map = game.add.tilemap('level1map');map.addTilesetImage('mariotileset');layerenemy = map.createLayer('enemylayer');layerbackground = map.createLayer('background');layermain = map.createLayer('mainlayer');layermain.resizeWorld();

you only need to call resizeWorld on one of your layers...

 
 
Link to comment
Share on other sites

Thanks for your response, but can't made it work neither...

 

There are no errors on browser console. I'm starting to think that's maybe I'm creating the map "wrong". There's a "correct" way to create maps in Tiled for Phaser import??

That's how my map looks like in Tiled:

phaser.png

 

And the code again:

var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });function preload() {    game.load.tilemap('map', 'assets/tilemaps/maps/adv.json', null, Phaser.Tilemap.TILED_JSON);    game.load.image('tiles', 'assets/tilemaps/tiles/adv.png');}function create() {    var map = game.add.tilemap('map');    map.addTilesetImage('advance wars sprites','tiles');    layer2 = map.createLayer('layer2');    layer1 = map.createLayer('layer1');    layer1.resizeWorld();}

I'm using Phaser version v2.0.2 "Ghealdan" - Built: Fri Mar 28 2014 01:30:50

Link to comment
Share on other sites

Not sure if this matters but I have 3 layers and I create them in the order (layer1, layer2, layer3) and I notice you have layer2 before layer1. Not sure if that matters.

 

Have you tried commenting out layer 2 and only leaving 1 to see if you get anything?

 

Can you post your map file here also.

Link to comment
Share on other sites

I know this is an easy fix because I use multiple layers but my second layer is object layer.

Maybe the reason is because you're loading layer 2 before layer 1. Load the base layer1 first, then the 2nd layer after the first is loaded.

Code seems fine to me. Just make sure layer 1 is called layer 1 in the json. Same for layer 2, make sure they all match the json data file.

Link to comment
Share on other sites

Thanks for your replies, guys.

 

But, if I just switch layer creation, like:
layer1 = map.createLayer('layer1');

layer2 = map.createLayer('layer2');

 

the opposite happens: just the layer1 shows up, and layer2 is nowhere to be found :(

If I create only one layer, everything's fine. Both layer get rendered. Ah, and yes, the layer names are correct, same name in the json file...

The .json map data is attached.

adv.zip

Link to comment
Share on other sites

Also, if I take the mario example (Tilemaps>mario), open it in Tiled, and add another layer, it doesn't render...

Maybe it's a Tiled version especific error? Or Phaser version specific?

 

Anyone who got this working could post some TIled json example, just for comparison purposes?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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