englercj / phaser-tiled

A tilemap implementation for phaser focusing on large complex maps built with the Tiled Editor.
MIT License
290 stars 31 forks source link

Improve body combine algorithm #13

Open englercj opened 9 years ago

englercj commented 9 years ago

When converting a tilemap layer into physics bodies the current algorithm will combine adjacent bodies on an X axis, resulting in bodies which is less than one-per-tile but still can present problems with performance or edge sticking (by stacking strips).

This algorithm should really combine all adjacent bodies into a single polygon.

JimVliet commented 8 years ago

Hey I made my own kind of version recently and while it's not perfect, it works alright. Result is here: http://jimvliet.github.io/HTML5-Game/objectConverter

The code is in this file: https://github.com/JimVliet/HTML5-Game/blob/master/scripts/functionFile.ts

It works like this: It starts at the top left and goes to the bottom right. Everytime it finds a solid object which isn't already used it will create a rectangle with the largest possible area from that position. Then the tiles used in that rectangle won't be able to be used again.

If you have any questions, feel free to ask.

EDIT: This is my current game: http://jimvliet.github.io/HTML5-Game/ in which this is used