Good, performant method for handling multiple footstep sounds across different surfaces?

0 favourites
  • 6 posts
From the Asset Store
High quality footstep sounds that're perfect, for adding realism to any project needing lifelike footstep audio.
  • Hi all, my game has different surfaces such as grass, rock, metal etc and I am wanting to play different footsteps as the character runs across these.

    My levels are large, varied and are primarily built using tilemaps so my first thought was to create a colour coded tilemap placed underneath my collision tiles and check if the player is overlapping a particular index in that and then play the sounds as needed. I like this method because I can just paint in areas and they will match up easily with my artwork. I haven't put it into practice yet, but it got me thinking - is that actually the best way to do this?

    I would have to constantly be looping through the tilemap indexes right? Or would I simply be saving myself time if I had several sprites and stretched them as needed across areas and then made them invisible at runtime? Would this be more or less performant? Does anyone have any experience or insights on the best way to do this from both a performance and maintenance perspective, bearing in mind that we are dealing with large layouts here. I realise for small projects the performance difference may be inconsequential. Thanks for any guidance!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Using a second tilemap is a good idea actually. Comparing the tile number at a position is a O(1) operation, and that's optimal performance wise. In your events you would then check the number of the tile underneath the player to determine which sound to play.

    The only downside may be that you basically need to have a whole second copy of your main map as a tilemap, which increases memory usage, but I wouldn't worry too much about that, unless your map is really huge and your tiles are relatively small.

  • Following on from BigBuckBunny's suggestion, rather than having a second tilemap you could associate the tile IDs to sounds in a 1d array and then reference the array when deciding which sound to play. The benefit of this would be that if you make any adjustments to the map or the sound mapping you only need to adjust the values in the array, rather than redraw the map.

    e.g:

    On sound "walk" ended & Avatar isWalking,

    play (byname) arrayWalksounds.At(TileAt(Avatar.X, Avatar.Y))

  • Thanks both of you for the insights! The array idea is definitely interesting I will have a play around with it! Thank you

  • Here is how we do it in our game. We have a bunch of variables containing tile IDs for different surfaces. Note that each list starts and ends with a comma:

  • Thanks so much, I will study this!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)