gwartney Posted January 5, 2017 Share Posted January 5, 2017 So I have not quite figured this out. But I am trying to set two diffrent collisions for two seprate tile map layers. For instance I have a ground layer that the player can run on and a obstacle such as spikes that a player will be able to run into. But I dont want it to overlap. So I have attempted something like this in the create function. map = game.add.tilemap('GroundTilePrototype'); // Add the tileset to the map map.addTilesetImage('GroundTileSet'); // Create the layer by specifying the name of the Tiled layer layer = map.createLayer('Tile Layer 1'); // Set the world size to match the size of the layer layer.resizeWorld(); // Enable collisions for the first tilset element map.setCollision(2); layer2 = map.createLayer('Tile Layer 2'); //set spike colosion map.setCollision(1); And I thought I could do something like this in the update function. But It will only work for the first layer. Could any one point me toward the right direction? game.physics.arcade.collide(player,layer); game.physics.arcade.collide(player,layer2); Thanks for the help. Link to comment Share on other sites More sharing options...
drhayes Posted January 5, 2017 Share Posted January 5, 2017 What doesn't work? The player can literally walk through tile 1 in layer2? What if you combine those two lines into one: "map.setCollision([1,2]);"? Link to comment Share on other sites More sharing options...
gwartney Posted January 5, 2017 Author Share Posted January 5, 2017 well the player wont be able to walk through neither when both are set and if i have only one set it can only walk on one or the other. And I have not tried your way so I will go and check. Link to comment Share on other sites More sharing options...
gwartney Posted January 5, 2017 Author Share Posted January 5, 2017 So i tried it but still the same issue it will only collide with layer 1 but not layer 2 Link to comment Share on other sites More sharing options...
drhayes Posted January 6, 2017 Share Posted January 6, 2017 It's probably because layer1 has become the current layer in the tilemap. Try specifying it completely, like this: "map.setCollision([1,2], true, layer1); map.setCollision([1,2], true, layer2);". See if that helps. Link to comment Share on other sites More sharing options...
Recommended Posts