Heppell08 Posted April 22, 2014 Share Posted April 22, 2014 Yeah the topic pretty much explains. My issue is I'm making a topdown map for testing at the minute but for some reason, I can't get the 2nd layer to collide.I can get the first main layer to collide but can't collide the 2nd. What I'm after is the main bottom layer to have no collisions at all and have the 2nd layer be the collide layer.Now I've switched the layers but that removes the 2nd layer under the main layer etc.When I debug I get no bounds on the second layer. They both are in the same json file.I tried var layer2 and created the map with everything visible as should be but just doesn't collide. I've also given the update the arcade collide for player and layer.Any ideas? Link to comment Share on other sites More sharing options...
drhayes Posted April 22, 2014 Share Posted April 22, 2014 Can you post the code you use to load the tilemap and its layers? As well as the collision code? Link to comment Share on other sites More sharing options...
Heppell08 Posted April 22, 2014 Author Share Posted April 22, 2014 The code is standard:Layer1 = map.createLayer('TileLayer1');Layer2 = map.createLayer('TileLayer2');Then I have:Layer1.resizeWorld();Layer2.resizeWorld();Then my update is:this.game.physics.arcade.collide(player, Layer2); Link to comment Share on other sites More sharing options...
marvster Posted April 22, 2014 Share Posted April 22, 2014 Does layer2 has a physical body?That's what I've done: [..]create: function() { [..] game.physics.arcade.enable(this.player); [..] this.layer1 = this.map.createLayer('background'); //no collision here this.layer2 = this.map.createLayer('obstacles'); //collides this.layer1.resizeWorld(); this.layer2.resizeWorld(); game.physics.arcade.enable(this.layer2); this.map.setCollisionByExclusion([],true,this.layer2); //collides on every tile [..] },update: function() { game.physics.arcade.collide(this.player, this.layer2); [..]}, [..]And it works: http://tannhauser-gate.net/projects/games/tilemap-test/ (currently here it is layer3, 'cause, layer2 collides different, see: http://tannhauser-gate.net/projects/games/tilemap-test/js/test.js) Link to comment Share on other sites More sharing options...
Heppell08 Posted April 22, 2014 Author Share Posted April 22, 2014 Hmmm, I didn't set any physical body property to my 2nd layer. I'll check your code against mine soon and see but looks like you're doing the same as me. Thanks! Link to comment Share on other sites More sharing options...
marvster Posted April 22, 2014 Share Posted April 22, 2014 Hmmm, I didn't set any physical body property to my 2nd layer. I'll check your code against mine soon and see but looks like you're doing the same as me. Thanks! Does collision not always require a physical body? Thought so, as it's not known to ARCADE otherwise. Just let me know your feedback, I owe you one. Link to comment Share on other sites More sharing options...
Heppell08 Posted April 22, 2014 Author Share Posted April 22, 2014 Yeah I totally overlooked the enabling of the layer because of the first layer (automatically?) having a physical body. All the better for knowing now though thanks! Link to comment Share on other sites More sharing options...
Heppell08 Posted April 22, 2014 Author Share Posted April 22, 2014 Thanks, works like a charm! Link to comment Share on other sites More sharing options...
Recommended Posts