Is it possible to use the tile IDs of a tilemap to play specific sounds?

0 favourites
  • 4 posts
From the Asset Store
A set of board games to make your day joyful. Play, Enjoy, Relax
  • Hi everyone,

    I'm creating a 2D platformer and my levels are built with a tilemap. For the game's sound effects, I was wondering if it's possible to use the tile IDs of the tilemap (the numbers that appear for each tile in the tilemap panel) to play different sounds when my character overlap or collide with these tiles.

    For example, if my character overlaps with tile ID 4 (a tile with grass) -> play sound 1 (sound of footsteps on grass), if my character overlaps with tile ID 14 (a tile with stone) -> play sound number 2 (sound of footsteps on stone), etc...

    If anyone has any ideas, it would help me a lot! As a last resort, I was thinking of placing invisible sprites that would trigger the different sounds, but if there's a way to use the IDs of each tile, that would be perfect!

    Tagged:

  • There could be a better way but my approach would be to try PositionToTile where it would convert the player's position X,Y to a specific tile position, with which you can grab the TileID using 'Compare tile at' position. This should in theory give the ID of the current tile that the player is overlapping and then you can say for example if ID=1 play audio1, give it a go I kind of want to try it myself but too lazy to set up a tilemap :)

  • Thanks you very much lionz!

    It works great! I just had to offset the Y with something like :

    Tilemap.PositionToTileY(Character.Y+10)

    because it was checking the position on the middle of the character and not on the tile below his feets. It works very well to get the tile IDs in the ground, thanks again!

    So now I have a new problem to solve, by shifting the Y downwards, now I'm not getting the IDs of the tiles on the ceiling, if my character collides with what's above his head, and the same for lateral collisions.

    I'll think about it, but it's already very promising like that, and a big step to see that I can do something with these tile IDs!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Try different conditions linked to the movement controls, on down key pressed you do +10 to the Y, if you press up it's -10 on the Y and might catch the tiles.

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