0
\$\begingroup\$

My problem with the collision here is more to do with how to decide which tile the player is in. Each quad of the map is 16 pixels squared (Vertex array), and the player moves in 1 pixel jumps. Because of this I cannot think of a way to decide which quad the player is in.

I am not sure if I am just missing something, but does anyone have an idea of how to do this?

\$\endgroup\$
1
\$\begingroup\$

This is a classic collision detection problem. Thinking about it in pixels isn't the right way of going about it though.

What you need to do is have a geometric representation of your player and the boundaries of your tile map. This might be as simple as just having a bounding box on your player and on each tile.

When the player's bounding box intersects a tile's bounding box, the player is colliding with or "on" that tile. Depending on how you construct your movement the player could be "on" many tiles at the same time.

Checking the player's bounding box against every tile would also be pretty inefficient. You don't want to check the player's bounding box against tiles that it's nowhere near intersecting. This is solved with a Spatial Partitioning algorithm and for your needs it sounds like you'd want to implement a Quad Tree if you want the player to be able to be intersecting multiple tiles at once.

I hope that makes sense!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.