Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

How do you set up collision by tiles and/or layer


aberrantmind
 Share

Recommended Posts

I've been stuck on this problem for a few days now. I'm trying to set collisions by layer and cannot figure it out.

 

I can set collisions between sprites and groups, but I can't get tiles to work.

 

here's the relevant code:

 

in load:


 

game.load.tilemap('overworld', 'assets/testSuite.json', null, Phaser.Tilemap.TILED_JSON);

 

game.load.tileset('tiles', 'assets/overworld.png',16,16);

 


 

in create:

map = game.add.tilemap('overworld');

 

tileset = game.add.tileset('tiles');

tileset.setCollision(26, true, true, true, true);

// the above doesn't seem to do anything

//I want to add collision with the player against a specific tile index against a specific layer:

//26 are the tree tiles which are on layer2

//97 is the ocean tile which are on layer0

 

layer0 = game.add.tilemapLayer(0, 0, 800, 600, tileset, map, 0);

layer0.resizeWorld();

 

layer1 = game.add.tilemapLayer(0, 0, 800, 600, tileset, map, 1);

layer2 = game.add.tilemapLayer(0, 0, 800, 600, tileset, map, 2);

layer3 = game.add.tilemapLayer(0, 0, 800, 600, tileset, map, 3);

 

From what I understand tilemapLayer is just for rendering, tile and tilesets are for setting collisions. 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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