Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimise the collision checking not to check all the tiles #35

Open
sionleroux opened this issue Jan 21, 2022 · 0 comments
Open

Optimise the collision checking not to check all the tiles #35

sionleroux opened this issue Jan 21, 2022 · 0 comments

Comments

@sionleroux
Copy link
Owner

Right now the collision logic starts by looping through all 8100 tiles to check to see if the cricket is colliding with any of them. Really it should only need to check the (at most) 4 tiles it's touching at the moment. Last time I tried it with ldtk's Tile At function but then I found out that that is internally looping over all the tiles so that made it worse because we were doing that 4 times instead of one, but I think this should be possible if you use some simple maths knowing:

  • the cricket's coordinates
  • the relative coordinates of its hitbox's 4 corners
  • the size of tiles in the map and the map size

this should let let you be able to convert a given coordinate in pixels to a row and column number for the tiles and look up only those for you're interested in from the tiles arrays without having to loop through them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant