douglas Posted September 22, 2016 Share Posted September 22, 2016 i have a question because there is no collision with the layer here is the code, also i have added the right tile IDs var game; var map; var layer, layer1, layer2; var player; var cursors; game = new Phaser.Game(640, 480, Phaser.CANVAS, 'Zelda Mysteries of PhaserIO', { preload: preload, create: create, update: update, render: render }); function preload() { game.load.tilemap('hyrule', 'assets/tiles/hyrule.json', null, Phaser.Tilemap.TILED_JSON); game.load.image('light_world', 'assets/tiles/light_world.tiles.png'); game.load.spritesheet('link', 'assets/sprites/walking.tunic.png', 24, 32, 55); } function create() { //World map = game.add.tilemap('hyrule'); map.addTilesetImage('light_world.tiles', 'light_world'); //layer1 = map.createLayer('Calque de Tile 1'); layer2 = map.createLayer('Calque 2'); layer2.resizeWorld(); game.physics.startSystem(Phaser.Physics.ARCADE); map.setCollisionBetween(1078, 1085); map.setCollisionBetween(1255, 1258); game.world.setBounds(0, 0, 1280, 960); //Player player = game.add.sprite(50, 150, 'link'); player.scale.set(2); player.smoothed = false; player.animations.add('right', [0, 1, 2, 3, 4, 5, 6, 7], 16, false); player.animations.add('up', [12, 13, 14, 15, 16, 17, 18], 16, false); player.animations.add('left', [33, 34, 35, 36, 37, 38, 39, 40], 16, false); player.animations.add('down', [44, 45, 46, 47, 48, 49, 50, 51], 16, false); game.physics.enable(player); game.camera.follow(player); cursors = game.input.keyboard.createCursorKeys(); } function update() { game.physics.arcade.collide(player, layer2); player.body.collideWorldBounds = true; player.body.velocity.x = 0; player.body.velocity.y = 0; var speed = 160; if (cursors.right.isDown) { game.camera.x += 4; player.body.velocity.x = +speed; player.animations.play('right'); } else if (cursors.up.isDown) { game.camera.y -= 4; player.body.velocity.y = -speed; player.animations.play('up'); } else if (cursors.left.isDown) { game.camera.x -= 4; player.body.velocity.x = -speed; player.animations.play('left'); } else if (cursors.down.isDown) { game.camera.y += 4; player.body.velocity.y = +speed; player.animations.play('down'); } else { player.animations.stop(); } } function render() { game.debug.spriteInfo(player, 20, 32); } hyrule.json Link to comment Share on other sites More sharing options...
DegGa Posted September 22, 2016 Share Posted September 22, 2016 Do you get any errors in the console?? Also I can't find a tile with the id 1078 in the JSON file? Link to comment Share on other sites More sharing options...
nazimboudeffa Posted October 16, 2016 Share Posted October 16, 2016 Order of layer in tile editor is important for collision layer1 = map.createLayer('Calque de Tile 1'); layer2 = map.createLayer('Calque 2'); layer1.resizeWorld(); map.setCollisionBetween(1366, 1373, true, layer2); Link to comment Share on other sites More sharing options...
Recommended Posts