D
Daniel White
Guest
When my player sprite shoots it plays the gun shot sound and the shoot animation but while the shoot animation is playing you can keep clicking to play more gun shot sounds. how do I make it so that you can't play that sound again until the animation has finished?
this is my step event sound at the bottom:
this is my step event sound at the bottom:
Code:
//Controls
if(state == "WALK" || state == "IDLE"){
if keyboard_check(ord("D")) {
x += walkSpeed;
image_speed = walkSpeed / 3;
sprite_index = spr_walk;
facing = 1;
state = "WALK";
} else if keyboard_check(ord("A")) {
x -= walkSpeed;
image_speed = walkSpeed / 3;
sprite_index = spr_walk;
facing = -1;
state = "WALK";
} else {
state = "IDLE";
}
}
switch(state) {
case "IDLE":
image_speed = 0;
sprite_index = spr_idle;
walkSpeed = 0.6;
if mouse_check_button(mb_right) {
state = "AIM";
}
break;
case "AIM":
if sprite_index!=spr_aim {
image_index = 0;
sprite_index = spr_aim;
image_speed = 1;
}
if(animation_end()){
image_speed = 0;
}
else if(floor(image_index) == 0){
image_speed = aimSpeed / 3;
}
if mouse_check_button_pressed(mb_left) {
state = "SHOOT";
sprite_index = spr_shoot;
image_index = 0;
image_speed = 1;
}
else if(!mouse_check_button(mb_right)){
state = "IDLE";
}
break;
case "SHOOT":
//Once animation ends, return to AIM state last frame (4)
if(animation_end()){
sprite_index = spr_aim;
image_index = 4;
state = "AIM";
}
break;
case "WALK":
//Press SHIFT to run
if keyboard_check(vk_shift) {
walkSpeed = 1.1;
}
break;
}
//Sound effects
//9mm gun sound
if (mouse_check_button_pressed(mb_left) and mouse_check_button(mb_right)){
audio_play_sound(snd_9mm, 5, false)
}