danteAGAIN Posted May 29, 2017 Share Posted May 29, 2017 Hello everyone, I am beginner with phaser, i am French and my english is not very nice. I need your help, i am blocked on a collide function. I want my character to collide with my second layer (tree, montain, statue..). (i use tiled map editor and export in json). my code : function preload: game.load.tilemap('map', 'assets/tilemaps/maps/map.json', null, Phaser.Tilemap.TILED_JSON); game.load.image('tiles', 'assets/tiles/tiles.png'); game.load.spritesheet('perso', 'assets/sprite/spritetest.png', 32, 47); function create : game.physics.startSystem(Phaser.Physics.ARCADE); map = game.add.tilemap('map'); map.addTilesetImage('tiles'); layer = map.createLayer('layer1'); layer2 = map.createLayer('layer2'); layer2.resizeWorld(); map.setCollisionBetween(0,2000); //PLAYER // ajout player et parametre player = game.add.sprite(250, 50, 'perso'); // We need to enable physics on the player game.physics.arcade.enable(player, Phaser.Physics.ARCADE); function update : game.physics.arcade.collide(player, layer2); i show an image for understand my problem. Thx to read my message Link to comment Share on other sites More sharing options...
fernando mondo Posted May 30, 2017 Share Posted May 30, 2017 I am from Brazil then my english is not very nice too. How is the player moved? Are you moving with velocity or moving a set amount of x specified? usually you need use something like this: if (controls.left.isDown) { player.animations.play('run') player.scale.setTo(-1, 1) player.body.velocity.x = -player.walkingSpeed } another tip is using collision only in the layer that you want: map.setCollisionBetween(0, 2000, 'layer2') Link to comment Share on other sites More sharing options...
danteAGAIN Posted May 31, 2017 Author Share Posted May 31, 2017 On 29/05/2017 at 9:13 PM, [email protected] said: On 29/05/2017 at 9:13 PM, [email protected] said: My character can move , the problem is the collision with the layer 2. I have try to use " map.setCollisionBetween(0, 2000, 'layer2') but collision do not work. just for info, I use this : if (cursors.left.isDown) { // Move to the left player.body.velocity.x = -150; player.animations.play('left'); } but I think is not my problem because my character can run and stop. I dont know why, i can collide my layer( who is my background) but i cant collide my second layer (tree, montain..) Link to comment Share on other sites More sharing options...
danteAGAIN Posted May 31, 2017 Author Share Posted May 31, 2017 My problem is resolved , i need to write: map.setCollisionBetween(234, 235, true, layer2) ===> i's important to write true and layer2 If someone need this answer. Link to comment Share on other sites More sharing options...
Recommended Posts