• 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!

(SOLVED) Multi-Footsteps?

Fixer90

Member
Code:
if(keyboard_check(ord("S"))) && (global.keylock == false)
{
    sprite_index = spr_wplayer_walking_down;
    phy_position_y += 1.2;
    image_speed = 0.15;
    if(floor(image_index) == 0) && (footstep_1 == false)
    {
        audio_play_sound(snd_footstep_1, 10, false);
        footstep_1 = true;
        footstep_2 = false;
    }
    
    if(floor(image_index) == 0) && (footstep_2 == false)
    {
        audio_play_sound(snd_footstep_2, 10, false);
        footstep_2 = true;
        footstep_1 = false;
    }
}

if(keyboard_check(ord("A"))) && (global.keylock == false)
{
    sprite_index = spr_wplayer_walking_left;
    phy_position_x -= 1.2;
    image_speed = 0.15;
    if(floor(image_index) == 0) && (footstep_1 == false)
    {
        audio_play_sound(snd_footstep_1, 10, false);
        footstep_1 = true;
        footstep_2 = false;
    }
    
    if(floor(image_index) == 0) && (footstep_2 == false)
    {
        audio_play_sound(snd_footstep_2, 10, false);
        footstep_2 = true;
        footstep_1 = false;
    }
}

if(keyboard_check(ord("D"))) && (global.keylock == false)
{
    sprite_index = spr_wplayer_walking_right;
    phy_position_x += 1.2;
    image_speed = 0.15;
    if(floor(image_index) == 0) && (footstep_1 == false)
    {
        audio_play_sound(snd_footstep_1, 10, false);
        footstep_1 = true;
        footstep_2 = false;
    }
    
    if(floor(image_index) == 0) && (footstep_2 == false)
    {
        audio_play_sound(snd_footstep_2, 10, false);
        footstep_2 = true;
        footstep_1 = false;
    }
}

if(keyboard_check(ord("W"))) && (global.keylock == false)
{
    sprite_index = spr_wplayer_walking_up;
    phy_position_y -= 1.2;
    image_speed = 0.15;
    if(floor(image_index) == 0) && (footstep_1 == false)
    {
        audio_play_sound(snd_footstep_1, 10, false);
        footstep_1 = true;
        footstep_2 = false;
    }
    
    if(floor(image_index) == 0) && (footstep_2 == false)
    {
        audio_play_sound(snd_footstep_2, 10, false);
        footstep_2 = true;
        footstep_1 = false;
    }
}

if(keyboard_check_released(ord("S"))) && (global.keylock == false)
{
    sprite_index = spr_wplayer_idle_down;
    image_speed = 0.027;
}

if(keyboard_check_released(ord("A"))) && (global.keylock == false)
{
    sprite_index = spr_wplayer_idle_left;
    image_speed = 0.027;
}

if(keyboard_check_released(ord("D"))) && (global.keylock == false)
{
    sprite_index = spr_wplayer_idle_right;
    image_speed = 0.027;
}

if(keyboard_check_released(ord("W"))) && (global.keylock == false)
{
    sprite_index = spr_wplayer_idle_up;
    image_speed = 0.027;
}
So what I've got here is the step event for my player (obj_player_world). In the create event, he starts with two variables:
Code:
footstep_1 = false;
footstep_2 = true;
So I've set up a perfect (or so I thought) footstep loop that would play on the right image indexes (I even floored them). The problem? It makes the sound of like, 3 or 4 footsteps stacked whenever it's suppose to happen (like a vibrating sound or something).

Is there a problem in my code that makes them play a bunch of times per image index?
 

Alexx

Member
Code:
if(floor(image_index) == 0) && (footstep_1 == false)
   {
        audio_play_sound(snd_footstep_1, 10, false);
        footstep_1 = true;
        footstep_2 = false;
    }
 
    if(floor(image_index) == 0) && (footstep_2 == false)
    {
        audio_play_sound(snd_footstep_2, 10, false);
        footstep_2 = true;
        footstep_1 = false;
    }
It will the play sound when footstep_1 is false, and also set foot_step_2 to false, so the second block is executed straight after.
You'd probably be better setting a short alarm, and when executing play the sound and change the true / false in that.
 

Fixer90

Member
It will the play sound when footstep_1 is false, and also set foot_step_2 to false, so the second block is executed straight after.
You'd probably be better setting a short alarm, and when executing play the sound and change the true / false in that.
Turns out you're right... but not in the way you might think. I forgot that 2nd footstep sound is suppose to have a separate image index. *FACE-PALM!*
Now I've got a perfect image index footstep loop! Probably wouldn't have found that index error had it not been for you. Thanks!
 
Top