|
Footsteps sound effect |
childski
Member #17,771
June 2020
|
Hello, I am trying to implement a footsteps sound effect in my 2D RPG game. Currently, I have this function in my game to control the player: 1if(state != IDLE)
2 {
3 active = true;
4 if(al_key_down(&keystate, ALLEGRO_KEY_DOWN))
5 {
6 character1.y += movespeed;
7 dir = DOWN;
8 al_play_sample(footsteps,1,0,1,ALLEGRO_PLAYMODE_ONCE,NULL);
9 }
10 else if(al_key_down(&keystate, ALLEGRO_KEY_UP))
11 {
12 character1.y -= movespeed;
13 dir = UP;
14 al_play_sample(footsteps,1,0,1,ALLEGRO_PLAYMODE_ONCE,NULL);
15 }
16 else if(al_key_down(&keystate, ALLEGRO_KEY_RIGHT))
17 {
18 character1.x += movespeed;
19 dir = RIGHT;
20 al_play_sample(footsteps,1,0,1,ALLEGRO_PLAYMODE_ONCE,NULL);
21 }
22 else if(al_key_down(&keystate, ALLEGRO_KEY_LEFT))
23 {
24 character1.x -= movespeed;
25 dir = LEFT;
26 al_play_sample(footsteps,1,0,1,ALLEGRO_PLAYMODE_ONCE,NULL);
27 }
28 else
29 active = false;
I have tried to use ALLEGRO_PLAYMODE_LOOP, but it loops the sound effect very slowly (like a 1 second break before the sound effect loops itself). Is there any better way to implement this sound effect? Thank you so much! |
Paulinek13
Member #17,702
May 2020
|
Hi, One solution may be like this: 1// ...
2
3case ALLEGRO_EVENT_TIMER:
4{
5 // ...
6
7 if(!(al_get_timer_count(timer) % 12)) // adjust the number
8 {
9 switch(runner.state)
10 {
11 case RUNNER_STATE::WALK_L:
12 case RUNNER_STATE::WALK_R: al_play_sample(sample_runner_steps, .5f, 0.f, 1.f, ALLEGRO_PLAYMODE_ONCE, 0); break;
13
14 default: break;
15 }
16 }
17 // ...
18}
19
20// ...
I'm not sure if it is actually better, but it works fine for me.
|
childski
Member #17,771
June 2020
|
@Paulinek13: hi, thanks for your input! I have tried several methods using a timer but it still doesn't work properly. It only plays once every 1~2 seconds. |
Paulinek13
Member #17,702
May 2020
|
Now I guess that your footsteps sample lasts,
|
pmprog
Member #11,579
January 2010
|
Just something else to consider - how long does it take for your game loop take? Also, what options did you select when creating your voice and mixer?
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
You could loop the sample, and pause it when they are not walking. Are you trying to sync the sample with your player's footsteps? My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|