Footsteps sound on different surface


Can you tell me the best way to detect what is the image the player is standing on in order for me to change the footstep sound to reflect that type of surface

The problem is with the performance of the searching of that tile the player is on (because its not a fixed grid like Tiled editor)

Im currently using RTree and its good but i would like to know better performing way.

I don’t know a better way, but it’s possible you can do that search less frequently (100ms, 200ms?) than every game step.

This is the way I do it and I’m using it on a big map with a lot of body objects on it and is working perfectly I never faced a performance drop before.

I add in Tiled property for ground tiles what is what for example type wood, stone, grass etc.

In my input class where I control the player with keys, I added a check where I get the position of the player and check what tile is he on, get property and check what is it and play sound for it. Of course, you will also need to handle sound management to not play all at once, where to stop etc.

However, I’m not doing check in update function but the input function where I move the player I check tiles only when I press keys to move.

you can see example here