Jump to content

How to add multiple csv tile layers to a game


rockleaf99
 Share

Recommended Posts

I've just started with phaser and I'm looking into csv tile maps. 

I'm using tiled to create the maps with multiple layers to separate parts of the map such as collision, npc, etc.

Exporting the map to csv leads to multiple csv files being created which is what im unsure on how to handle with phaser.

To get around this i've combined the layers before exporting them however this is not ideal as I would prefer less coupling. 

A problem that I have faced is that i'm not sure how to add and reference multiple csv tile layers to a game based on the phaser documentation.
Reference: https://phaser.io/examples/v2/tilemaps/csv-map
Q1. Why is the parameter passed in 0 when creating a layer based on the csv tiles?

layer = map.createLayer(0);

Q2. How would I go about adding in a second layer so that it's part of the same map and is shown at the same time as the first layer?

function preload() {

    game.load.tilemap('map', 'assets/tilemaps/csv/catastrophi_level1.csv', null, Phaser.Tilemap.CSV);
    game.load.tilemap('map2', 'assets/tilemaps/csv/catastrophi_level2.csv', null, Phaser.Tilemap.CSV);
    game.load.image('tiles', 'assets/tilemaps/tiles/catastrophi_tiles_16.png');
game.load.image('tiles2', 'assets/tilemaps/tiles/catastrophi_tiles_16.png');

}

var map;
var layer;
var cursors;

function create() {

    //  Because we're loading CSV map data we have to specify the tile size here or we can't render it
    map = game.add.tilemap('map', 16, 16);

    //  Now add in the tileset
    map.addTilesetImage('tiles');
    
    //  Create our layer
    layer = map.createLayer(0);

    map2 = game.add.tilemap('map2', 16, 16);
    map2.addTilesetImage('tiles');
layer2 = map2.createLayer(?);// 0?

map.layers.push(layer2);//make sure both layers are on the same map?

 

 

Link to comment
Share on other sites

On 6/26/2017 at 2:07 PM, rockleaf99 said:

Q1. Why is the parameter passed in 0 when creating a layer based on the csv tiles?

0 is just the first layer. You can use it for any map type, but CSV maps need it because they have only one, unnamed layer.

On 6/26/2017 at 2:07 PM, rockleaf99 said:

Q2. How would I go about adding in a second layer so that it's part of the same map and is shown at the same time as the first layer?

I would just use JSON instead.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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