• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Making a sound on each tile moved

Geoff Jones

Member
Hello all, Im making a game similar to Ultima 5 where the movement is based on 16x16 grid squares. So each time you press up down left or right, it will jump 1 tile in that direction similar to this -

My question is, how do I get a sound to play at each step?
Here is the code I have for the movement
Code:
/// Move player

var xDirection, yDirection
xDirection =keyboard_check(vk_right) - keyboard_check(vk_left);
yDirection =keyboard_check(vk_down) - keyboard_check(vk_up);

x += xDirection *16
y += yDirection *16
This code is in a step even in the player object.

Thanks for your help :)
 

Tthecreator

Your Creator!
this is quite easy, open up the game maker manual by pressing F1 and type in sound there you will find all sound related functions.
Now import your sound into game maker(use the button next to new sprite and click the open icon)
Next look into the function audio_play_sound(whatever the name of your sound is, 10, false because you want your sound to play once)
If you want to be fancy you can use audio_play_sound_at()
 

Tthecreator

Your Creator!
btw, i forgot something....
You can put audio_play_sound in your code by checking if xDirection or yDirection is not equal to zero.
you code whould look like:

if !(xDirection=0) or !(yDirection=0) then{audio_play_sound(snd_whatever,10,false)}
 
G

GhostGK

Guest
Be careful of using sound functions in Step events.. Make sure you check if the particular sound is already playing, unless you want your sound to be played every step the condition is active..

Example..
Code:
//If movement is active
if xDirection != 0 ||  yDirection != 0
{
//if sound isn't already playing
if !audio_is_playing(snd_footstep)
    {
    //Play the sound
    audio_play_sound(snd_footstep, 10, false);
    }
}

Do note that since I'm referring to resource name, not the sound's ID.. So this would be problematic if you use same sound for other NPCs.. Assign the sound ID to a particular variable in such cases and refer to that variable..
Code:
player_footstep = audio_play_sound(snd_footstep, 10, false);
 
Top