Jump to content

Set tilemap tile bounding boxes in Phaser


TomLGD
 Share

Recommended Posts

Hi there,

 

I'am working on a small tile based game.

I use the tool "Tiled" for creating my tilemap and import it with phaser.

 

The map ist build of a 8x8 pixel grid in size.

BUT my tiles are actually 16x16 pixels in size.

 

I do this to habe some kind of "half position" for chests or wooden boxes and so on.

 

If I load it in Phaser it looks all right but the collision ist wrong.

Cause the grit is 8x8 pixels, the bounding boxes of the tiles are 8x8 pixels too...

 

How can I tell Phaser that it should use a bounding box with the double of width and height?

 

And I don't want to slize my 16x16 tiles in 4 8x8 tiles caue that would cause in four times higher collsion checkts^^

 

thanks in advance 

Tom

post-16790-0-80896400-1449845831.png

Link to comment
Share on other sites

I'm not 100% percent sure but I think Phaser does some optimisation regarding layers, that is, it builds up the collision rectangles regarding the collision tiles. So if 4 tiles are next to each other, Phaser might create a single rectangle collision hitbox for all 4. I'm not sure it's actually how it works but when you debug a layer that's what's displayed. Maybe it's just for the display ^^

 

Anyway I would go with splitting your rocks into 4 sub-tiles, it's the easiest and cleanest solution. Impact on performance won't probably even be noticeable. Or you could have 16x16 tiles and have the chests and other 8x8 things be sprites in the scene (not be a part of the map).

Link to comment
Share on other sites

Phaser does combine collisions into the smallest number of collisions possible.

 

You can use object.body.setSize(width, height, x, y) to change the collision

 

http://phaser.io/docs/2.4.4/Phaser.Physics.Arcade.Body.html#setSize

 

But I cannot looking for all tile of the same ID and then change the collision body of that tile. cause the tile object don't have such a property

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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