Adding a Footstep sound effect

Discussion in 'Programming' started by RetroNuva10, Jul 21, 2017.

  1. RetroNuva10

    RetroNuva10 Guest

    I am creating a top-down 2D game, and I want a sound effect to play for the character's footsteps. The character's walk animation consists of 2 frames, and its speed is 0.195. What is a good way to go about doing this?
     
  2. Neptune

    Neptune Member

    Joined:
    Jun 21, 2016
    Posts:
    1,031
    A simplistic way would be to have a global variable, which tells you if the player is moving or not.
    Then if the player is moving, have a little repeater playing the sound every so many steps.
    Code:
    if global.moving
    {
       count += 1;
       if (count == 15)
       {
          count = 0;
          //audio_play_sound(snd_foot_step,1,false);
       }
    }
    else
    {
       count = 0;
    }
     
  3. Siolfor the Jackal

    Siolfor the Jackal Member

    Joined:
    Jun 21, 2016
    Posts:
    758
    I know it's lazy but I often put my sound playing code in the animation end. Works great for simple animations. I just check if they're walking in the animation end and play the sound.
     
    RichHopefulComposer likes this.
  4. RichHopefulComposer

    RichHopefulComposer Member

    Joined:
    Jun 20, 2016
    Posts:
    1,380
    Animation End is one of the most useful events in GM. I use it for basically everything, haha!

    That said, if you have more than one step in your animation or whatever it might not work. In that case, I'd just tie my sounds to animation frames. If I want to play a footstep sound to frame 2, I'd just do something like:
    Code:
    If(floor(image_index==2) && floor(lastImageIndex !=2))
       scr_PlaySound(snd_Footstep);
    
    Then you could repeat for any other frames where feet hit the ground or whatever, too.
     
  5. Edu Shola

    Edu Shola Member

    Joined:
    Jul 1, 2016
    Posts:
    18
    animation end works like a charm, I just use an if statement to check if its the walking animation
     
  6. Kyon

    Kyon Member

    Joined:
    Jun 27, 2016
    Posts:
    469
    monster tip, add this under your audio play code:
    Code:
    p=random_range(.9,1.1);
    audio_sound_pitch(snd_foot_step, p);
    
     
    ktiix, Siolfor the Jackal and samyak like this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice