pixeltroid
Member
So I've been tinkering around with audio since yesterday and so far its been pretty easy to get a sound effect to play whenever a single event happens, like a death or a projectile creation.
I have been trying to create the sound of footsteps for my player. My audio file is that of a single footstep sound. So far I have managed to create the sound of a single footstep whenever the player lands on the ground, after jumps or falling. I did this by adding audio_sound_play(sfx_footstep,8,false) in players collision event with the ground object (obj_solid). This works pretty decently. But what I would really like is to have the footstep audio loop whenever he moves on the ground, but I haven't been able to achieve that.
I tried adding the same code to my left/right movement code, but the sound messes up by playing over itself and also by playing whenever the player jumps left or right.
I need the sound to:
a. play only whenever player is moving left/right on the ground.
b. Stop whenever he reaches a wall
c. Stop whenever he jumps
Any idea how I could achieve this?
Below is my players movement script:
Any help would be appreciated!
I have been trying to create the sound of footsteps for my player. My audio file is that of a single footstep sound. So far I have managed to create the sound of a single footstep whenever the player lands on the ground, after jumps or falling. I did this by adding audio_sound_play(sfx_footstep,8,false) in players collision event with the ground object (obj_solid). This works pretty decently. But what I would really like is to have the footstep audio loop whenever he moves on the ground, but I haven't been able to achieve that.
I tried adding the same code to my left/right movement code, but the sound messes up by playing over itself and also by playing whenever the player jumps left or right.
I need the sound to:
a. play only whenever player is moving left/right on the ground.
b. Stop whenever he reaches a wall
c. Stop whenever he jumps
Any idea how I could achieve this?
Below is my players movement script:
Code:
{
//moving left right
if keyboard_check(ord("D")) && place_free(x+4,y) && !keyboard_check(ord("A")) {
if (place_free(x,y+1)) {
if (place_free(x+4,y+vspeed)) {
sprite_index = spr_playerwalk;
image_speed = .3;
image_xscale = 2;
//facing="right";; //moving right
x+=4;
}
} else {
sprite_index = spr_playerwalk;
image_speed = .3;
image_xscale = 2;
x+=4;
//facing="right";; //moving right
}
} else if keyboard_check(ord("A")) && place_free(x-4,y) && !keyboard_check(ord("D")) {
if (place_free(x,y+1)) {
if (place_free(x-4,y+vspeed)) {
sprite_index = spr_playerwalk;
image_speed = .3;
image_xscale = -2;
x-=4;
//facing ="left"; //facing left
}
} else {
x-=4;
//facing ="left"; //facing left
sprite_index = spr_playerwalk;
image_speed = .3;
image_xscale = -2;
}
} else {
sprite_index = spr_playerstand;
image_speed = .1
}
if (!place_free(x,y+1)) {
//jumping
if keyboard_check_pressed(ord('W')) {
vspeed = -10;
}
} else {
sprite_index = spr_playerjump;
}
if (!place_free(x,y+1)) {
}
}