mrxj88 Posted January 16, 2017 Share Posted January 16, 2017 Quote Quote var Game = { preload: function() { game.load.tilemap('map', 'assets/map.json', null, Phaser.Tilemap.TILED_JSON); game.load.image('tiles', 'assets/dun.png'); game.load.image('player', 'assets/player.png'); }, create: function() { map = game.add.tilemap('map'); map.addTilesetImage('set1', 'tiles'); floors = map.createLayer('floor'); walls = map.createLayer('walls'); map.setCollisionBetween(1, 2000, true, 'walls'); floors.resizeWorld() player = game.add.sprite(50,50, 'player'); player.scale.setTo(0.2,0.2); game.physics.enable(player, Phaser.Physics.ARCADE); game.camera.follow(player); }, update: function() { game.physics.arcade.collide(player, walls); if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { player.x -= 2; } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { player.x += 2; } else if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { player.y -= 2; } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { player.y += 2; } } }; my player wont collide with tiles.. its a top down shooter Link to comment Share on other sites More sharing options...
jonteferm Posted January 17, 2017 Share Posted January 17, 2017 Looks like the walls is just a layer and not a group with enabled arcade physics. It will not work with the arcade.collide as it is just for stuff that have arcade physics. Have you tried to set collissionBetween to more than that? I have to set it to at least 3000 in my game for collision to take place. mrxj88 1 Link to comment Share on other sites More sharing options...
mrxj88 Posted January 17, 2017 Author Share Posted January 17, 2017 Hey thanks for the reply count doom. It was the movement from using: if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { player.x -= 2; i had to change it too: if (cursors.left.isDown) { player.body.velocity.x = -150; I also took your advice and changed it to 3000. Now the collision with the tiles work perfectly. Thank you again for the reply! jonteferm 1 Link to comment Share on other sites More sharing options...
Recommended Posts