Jump to content

Phaser 3 + Matter + Tiled: using polygon collision shapes


Rissk13
 Share

Recommended Posts

Hi, so I have a tilemap created with Tiled, and I defined my collisions as polygons in the tilesets themselves to get more accurate collisions. I was able to draw out where those polygons are with graphics but I'm a little confused at how I can set the collisions between my player sprite and those polygons with matter.

I sort of know about the setting categories and using setCollidesWith but I'm not sure what I need to create from the vertices of the polygons. I tried fromVertices but I couldn't figure out how to set the collision category on it.

Screen Shot 2018-07-05 at 11.20.54 PM.png

Link to comment
Share on other sites

You don't need to do anything with graphics, you need to define the collision shapes on the tileset in tiled:

http://docs.mapeditor.org/en/stable/manual/editing-tilesets/

 

If you set the tile layer to collide by property and have a matter body on the player they will inherently collide. If you don't define a collision shape on the tile in the collision editor in tiled then Phaser will give the tile a square body the size of the tile. You don't need to tell matter what to collide with what unlike arcade. Everything collides unless the body is a sensor.

 

Check this example to get a better idea:

https://labs.phaser.io/edit.html?src=src\game objects\tilemap\collision\matter platformer with wall jumping.js

 

Link to comment
Share on other sites

I was just using the graphics to visualize the collide shapes for debugging and learning the code.

I already created the collision shapes on the tileset in tiled, which is what the graphics are drawing (blue lines). You're saying if I just add a property to those tiles that I can grab by in Phaser, then set collision by property on the layer, it'll use the collision polygons I drew instead of the entire tile? I'll give it a go. Thanks.

Ah, and I think this line from the example is what I was looking for

this.matter.world.convertTilemapLayer(layer);

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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