pain99 Posted September 4, 2014 Share Posted September 4, 2014 Hei i have an issue and i cant figure out what i'm doing wrong. I have created a map with tiled and i added 2 tilesets. With the elements of the first tileset the player collides well. But with the elements of the second tileset it doesn't collide, it just goes trough the tiles. Please i need help Here's the Code:var game = new Phaser.Game(800, 600, Phaser.AUTO, '', {preload: preload, create: create, update: update});function preload(){ game.load.image('bonus', 'assets/bonus.png'); game.load.image('tileset', 'assets/tileset.png'); game.load.image('player', 'assets/player.png'); game.load.tilemap('map', 'assets/map.json', null, Phaser.Tilemap.TILED_JSON); }function create(){ game.physics.startSystem(Phaser.Physics.ARCADE); this.map = game.add.tilemap('map'); this.map.addTilesetImage('tileset'); this.map.addTilesetImage('bonus'); this.layer = this.map.createLayer('Kachelebene 1'); this.layer.resizeWorld(); this.map.setCollision(1); this.player = game.add.sprite(580, 480, 'player'); game.physics.arcade.enable(this.player); this.player.anchor.setTo(0.5, 0.5); this.player.body.gravity.y = 500; this.cursor = game.input.keyboard.createCursorKeys(); game.camera.follow(this.player); } function update(){ game.physics.arcade.collide(this.player, this.layer); if(this.cursor.left.isDown){ this.player.body.velocity.x = -200; } else if(this.cursor.right.isDown){ this.player.body.velocity.x = 200; } else { this.player.body.velocity.x = 0; } if(this.cursor.up.isDown && this.player.body.onFloor()){ this.player.body.velocity.y = -300; } }-sorry for my bad english. Link to comment Share on other sites More sharing options...
Kobaltic Posted September 5, 2014 Share Posted September 5, 2014 I think you have to pass an array with all the layers http://docs.phaser.io/Phaser.Tilemap.html#setCollision this.map.setCollision(1); this.map.setCollision(array); Link to comment Share on other sites More sharing options...
pain99 Posted September 5, 2014 Author Share Posted September 5, 2014 Thank you, it works! Link to comment Share on other sites More sharing options...
Kobaltic Posted September 13, 2014 Share Posted September 13, 2014 If my solution worked could you please mark it as the solution. This way others will know it is solved. TY. Link to comment Share on other sites More sharing options...
Recommended Posts