Jump to content

Help with Tiled


Recommended Posts

I've created a basic map using Tiled and imported it into my Phaser game.  That I can do without any trouble.


What I can't get quite get is how collision works.


I've loaded in the assets;


game.load.tilemap('level1', 'assets/tilemap.json', null, Phaser.Tilemap.TILED_JSON);

game.load.image('tiles', 'assets/tileset.png');
And added them to the game and got my ground layer:
map = game.add.tilemap('level1');
map.addTilesetImage('tileset', 'tiles');
ground = map.createLayer('ground');
I'm not sure where to go from here in regards to collision detection.  I've seen in tutorials about using setCollisionBetween( )  but I'm not sure what to pass in to this.  My map's json for ground is just 0 and 3.  I've tried    map.setCollisionBetween(3, 3); and     map.setCollisionBetween(1, 3);   each with on luck.
My players physics are turned on and I've set it to detect collisions in the update( ).  Not sure where to go from here.
Any help is appreciated.
Link to comment
Share on other sites

please try post Phaser 2 questions in the main Phaser forum http://www.html5gamedevs.com/forum/14-phaser/

(this is Phaser 3) 


anyway you can pass in those 2 tile indexes as an array


setCollision(indexes, collides, layer, recalculate)
Sets collision the given tile or tiles. You can pass in either a single numeric index or an array of indexes: [ 2, 3, 15, 20]. The collides parameter controls if collision will be enabled (true) or disabled (false).



in your case therefore

map.setCollision([0,3], true, 'ground')

although you can leave off the last 2 arguments as 'collides' param is true by default and you only have one layer



Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...