Mickety Posted April 10, 2018 Share Posted April 10, 2018 Phaser CE v2.10.3 So I have 2 tile layers in my Tiled map that use the same tileset. One for terrain, second is for trees over the existing map and other stuff that needs alpha channels. Preload game.load.tilemap('GameMap', 'TestMap.json', null, Phaser.Tilemap.TILED_JSON); game.load.image('TileSet', 'img/TileSet.png'); Create game.physics.startSystem(Phaser.Physics.ARCADE); GameMap = game.add.tilemap('GameMap'); GameMap.addTilesetImage('TileSet', 'TileSet'); layer = GameMap.createLayer('TileMap'); trees = GameMap.createLayer('Collideables'); GameMap.setCollision(7); // Deep water 1 GameMap.setCollision(17); // Deep water 2 GameMap.setCollision(27); // Dark GameMap.setCollision(37); // Trees layer.resizeWorld(); player = game.add.sprite(spawnX, spawnY, 'player'); game.physics.arcade.enable(player); game.camera.follow(player); player.body.collideWorldBounds = true; player.anchor.x = 0.5; player.anchor.y = 0.5; Update player.body.velocity.x = player.body.velocity.y = 0; game.physics.arcade.collide(player, layer); game.physics.arcade.collide(player, trees); The RESULT: Map terrain with sand, dirt and water draws correctly. (They are variable "layer") Trees also are being drawn in the right locations (They are variable "trees") Everything works, except for collisions. Player "collides" with water that is in the "layer" layer. But even though trees are being drawn they player doesn't collide with them. I basically did the same thing to "trees" creating a layer from it, which instantly adds it's graphics btw, and setup the collisions the way I did to layers. I've no idea why the player collides with deep water but not the trees. I'm at a loss. Why would player collide with deep water but not the trees? Link to comment Share on other sites More sharing options...
samme Posted April 10, 2018 Share Posted April 10, 2018 Set debug=true on both layers. Use the layer argument in setCollision. Link to comment Share on other sites More sharing options...
Mickety Posted April 10, 2018 Author Share Posted April 10, 2018 1 hour ago, samme said: Set debug=true on both layers. Use the layer argument in setCollision. Thank you kind sir. Changing to this: GameMap.setCollision(27); // Dark GameMap.setCollision(37, true, trees); // Trees worked exceptionally well. As usual - the fix was hiding really close but I failed to see it. Thank you. Cheers! Link to comment Share on other sites More sharing options...
Recommended Posts