polansk1 Posted May 12, 2018 Share Posted May 12, 2018 Hi! i need help! I have a tileset like a labyrinth and i will know how to set collisions between my Players and the walls of labyrinth(tileset). That's my actual code. All is working except that line: >>this.physics.world.collide( player, tileset ,null, this);<< What im doing wrong? function preload () { this.load.image('gameTiles', 'img/tileset_sprite.png'); this.load.tilemapTiledJSON('level1', 'maps/tileset_walls.json'); this.load.image('dude', 'img/dude.png'); } function create () { // platform............. this.map = this.add.tilemap('level1'); var tileset = this.map.addTilesetImage('tileset_sprite', 'gameTiles'); this.walls = this.map.createStaticLayer('walls', tileset); // player.............. player = this.physics.add.sprite(40, 40, 'dude'); // collisions........... this.physics.world.collide(player, tileset, null, this); player.setCollideWorldBounds(true); } Link to comment Share on other sites More sharing options...
samme Posted May 12, 2018 Share Posted May 12, 2018 You have to collide a tilemap layer, not a tileset. blackhawx 1 Link to comment Share on other sites More sharing options...
polansk1 Posted May 13, 2018 Author Share Posted May 13, 2018 Ok, so what variable i have to put instead tileset? i try it with this.walls and walls=this.walls but it's not working.. Link to comment Share on other sites More sharing options...
samme Posted May 13, 2018 Share Posted May 13, 2018 http://labs.phaser.io/index.html?dir=game objects/tilemap/collision/&q= Link to comment Share on other sites More sharing options...
polansk1 Posted May 13, 2018 Author Share Posted May 13, 2018 ty man!! i got it! function create(){ //platform this.map = this.add.tilemap('level1'); var tileset = this.map.addTilesetImage('tileset_sprite','gameTiles'); walls = this.map.createStaticLayer('walls', tileset,0,0); //player player = this.physics.add.sprite(40, 40,'dude'); walls.setCollisionBetween(1, 50); this.physics.add.collider(player, walls); //movimiento cursors = this.input.keyboard.createCursorKeys(); } working blackhawx 1 Link to comment Share on other sites More sharing options...
Recommended Posts