Jump to content

Tile collision with P2 and Tiled


psy_
 Share

Recommended Posts

Hello,

I'm trying to set collision with Tiled using the "Tile Collision Editor" on Tiled but I can't make it work on game. Basically I want to create a Polyline for each different Tiles so I don't have to copy/paste the polyline objects in the object layer.

 

 

LP0eN8J.png?1

 

For the moment I use one big Polyline object on a object layer that follow my map but it's not viable beause I have to draw all my tiles manually. 

Here is the part of the code I use to incorporate the object layer (I'm using ES6). It's working but it's not what I want : 

this._map = new Map(this._game, mapName);// ...this._map.addTilesetImage(tilesName, tilesName);this._blocksLayer = this._map.createLayer('collision');this._blocksLayer.resizeWorld(); this._game.physics.p2.convertTilemap(this._map, this._blocksLayer); this._game.physics.p2.convertCollisionObjects(this._map, 'test'); // where 'test' is the name of my layer
Thanks in advance for the help !
Link to comment
Share on other sites

'Test' should be the name of the object, that is in tile, not layer. Although I only think you can draw those polylines on an object, so double check that :)

 

Also, have you enabled p2 physics on your player's object.

 layerobjects_tiles = game.physics.p2.convertCollisionObjects(mymap,"objects1");   // this converts the polylines of the tiled - object layer into physics bodies.. make sure to use the "polyline" tool and not the "polygon" tool - otherwise it will not work!!

This is what I use within my game and the polylines are working as intended. Hmmm.

 

 

 

Edit: Wait, you said it's working so I got confusd, haha sorry. What's not exactly working? you want a more efficient way of creating polylines? You don't have to do per each tile IIRC you can drag across the map with them?

Link to comment
Share on other sites

Hey! thanks for your answer.

Sorry my explanation weren't that clear. So basically my tiled is like that : 

I have one layer for the tiles and another for the polyline objects. I use the polyline tool to draw the ground of the map (I follow the tiles). On the code part, I use the convertCollisionObjects to make the ground collide :

game.physics.p2.convertCollisionObjects(map, "<polyline_layer_name>");

So everything is working but the problem is that it's not really practical if I have, for ex, a huge map with a lot of tiles, I have to draw manually all the map...

To avoid this, I wanted to know if it's possible to use the Tile Collision Editor in Tiled so the ground is automatically generated (based on the tile polyline and not on the layer polyline).

I hope it's more clear. :)
 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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