hellojenny Posted June 19, 2014 Share Posted June 19, 2014 Hi. I've got a problem where my sprite only collides with the top most tiles and only the top edge of the tile. I'll attach my tileset file as well. Here is my code:var game = new Phaser.Game(1024, 768, Phaser.AUTO, 'wrapper', {preload: preload, create: create, update: update });function preload() { game.load.tilemap('map', '../images/map.json', null, Phaser.Tilemap.TILED_JSON); game.load.image('tiles', '../images/tiles.png'); game.load.atlasJSONHash('player', '../images/p3_walk.png', '../images/p3_walk.json');}var map;var groundLayer;var lavaLayer;var waterLayer;var icyLayer;var player;var cursors;function create() { game.physics.startSystem(Phaser.Physics.ARCADE); game.stage.backgroundColor = '#B8F1FF'; map = game.add.tilemap('map'); map.addTilesetImage('tiles', 'tiles'); lavaLayer = map.createLayer('Lava'); lavaLayer.resizeWorld(); waterLayer = map.createLayer('Water'); waterLayer.resizeWorld(); icyLayer = map.createLayer('IcyGround'); icyLayer.resizeWorld(); groundLayer = map.createLayer('Ground'); groundLayer.resizeWorld(); map.setCollisionBetween(7, 12, true, groundLayer); map.setCollisionBetween(17, 28, true, groundLayer); map.setCollisionBetween(13, 14, true, waterLayer); map.setCollisionBetween(15, 16, true, lavaLayer); map.setCollisionBetween(1, 6, true, icyLayer); //Create the player sprite player = game.add.sprite(75, game.world.height - 600, 'player'); game.physics.arcade.enable(player); //Player characteristics player.body.bounce.y = 0.25; player.body.gravity.y = 800; player.body.collideWorldBounds = true; player.body.linearDamping = 1; player.anchor.setTo(.5, 1); player.animations.add('run'); player.animations.play('run', 10, true); game.camera.follow(player); cursors = game.input.keyboard.createCursorKeys();}function update() { game.physics.arcade.collide(player, groundLayer); game.physics.arcade.collide(player, lavaLayer); game.physics.arcade.collide(player, icyLayer); game.physics.arcade.collide(player, waterLayer); player.body.velocity.x = 0; if (cursors.left.isDown) { player.scale.x = -1; player.body.velocity.x = -1200; } else if (cursors.right.isDown) { player.scale.x = 1; player.body.velocity.x = 1200; } if (cursors.up.isDown) { if(player.body.onFloor()) { player.body.velocity.y = -500; } }}Any help is appreciated! Thank you Link to comment Share on other sites More sharing options...
Kobaltic Posted June 20, 2014 Share Posted June 20, 2014 I had the same problem. Here is the answer. http://www.html5gamedevs.com/topic/3692-map-collision-isnt-working/ Link to comment Share on other sites More sharing options...
Recommended Posts