Hi,
how can i calculate the hit cell (col/row) of a tilemap (on collision)?
mercuryus
Develop games in your browser. Powerful, performant & highly capable.
You can use the tilemap method positionToTileX and positionToTileY to get tile position (col/row) from screen coordinates.
it would be something like
col : tilemap.positiontotileX(sprite.x)
row : tilemap.positiontotileY(sprite.y)
This returns the cell of the colliding sprite but not the cell the was hit
All I can think of is a rather terrible workaround.
Limitations include really fast balls not registering properly (because they've bounced off and are not overlapping anymore) and slightly inaccurate detection.
Here's the capx.
In short, I moved a set of 8 hit detection sprites to stay on the tiles surrounding the ball. When the ball hits the tilemap, it erases the tiles the hit detectors were on at that point.
clever solution but a bit too 'fuzzy' for my needs
Ashley: please add this event/function/property to the tilemap object.
This is similar to "getting the point of a collision between two objects" - objects don't collide at a point, they have an overlapping region. So in fact the collision would intersect a patch of tiles.
Would it be possible the provide the overlapping region for (each) collision?
Here's some more ideas on how to get the overlapping tiles:
You can probably get exactly like that pic by first using the raycast plugin to get the collision point then using the idea above to get the hit tile.