zachj95 Posted August 18, 2016 Share Posted August 18, 2016 Hey guys, I'm having a bit of an issue when importing my tilemap in from Tiled in to Phaser. It seems like just one of these tiles aren't establishing collision with the player. They're all in the same layer and set to collide with the player. Here's an image with layer.debug = true; on. https://gyazo.com/2a2fda1c24d5fb322c44fbaf3eb062bf Here's my code: // Create the state that will contain the whole game var game = new Phaser.Game(800, 600, Phaser.AUTO,'', { preload: preload, create: create, update: update }); function preload() { game.load.image('enemy', 'assets/sprites/bad.png'); game.load.image('player', 'assets/sprites/player.png'); game.load.image('coin', 'assets/sprites/coin.png'); game.load.image('wall', 'assets/sprites/wall.png'); game.load.tilemap('platformer', 'assets/mininicular.json', null, Phaser.Tilemap.TILED_JSON); game.load.image('tiles', 'assets/mytileset.png'); } var rightKey; var leftKey; var upKey; var player; var map; var layer; function create() { //BG Color, Initialize Physics, Enable World Physics game.stage.backgroundColor = '#ff00ff'; game.physics.startSystem(Phaser.Physics.ARCADE); game.world.enableBody = true; map = game.add.tilemap('platformer'); map.addTilesetImage('tileset', 'tiles'); map.setCollisionBetween(1, 5); layer = map.createLayer('Tile Layer 1'); layer.resizeWorld(); layer.debug = true; //Creates inputs for player (Arrow keys) leftKey = game.input.keyboard.addKey(Phaser.Keyboard.A); rightKey = game.input.keyboard.addKey(Phaser.Keyboard.D); upKey = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); //Adds player's sprite to the world player = game.add.sprite(70, 100, 'player'); player.scale.setTo(0.5, 0.5); game.physics.enable(player); //Sets player's gravity player.body.gravity.y = 600; player.body.collideWorldBounds = true; } function update() { game.physics.arcade.collide(player, layer); player.body.velocity.x = 0; //Updates what player input does if (rightKey.isDown) { player.body.velocity.x = 200; } else if (leftKey.isDown) { player.body.velocity.x = -200; } if (upKey.isDown && player.body.onFloor()) { player.body.velocity.y = -175; } } Link to comment Share on other sites More sharing options...
symof Posted August 18, 2016 Share Posted August 18, 2016 You are not setting the layer collision properly. Try map.setCollisionBetween(0, 5); OR map.setCollisionBetween(0, 6); OR map.setCollisionBetween(1, 6); Without seeing your actual tileset, that's where I'd place it. Link to comment Share on other sites More sharing options...
zachj95 Posted August 19, 2016 Author Share Posted August 19, 2016 This fixed it, Thanks! I didn't realize that it was actually between, I thought it just set it from one number to another. Link to comment Share on other sites More sharing options...
Recommended Posts