![]() |
|
Allegro sample/stream |
larzconwell
Member #13,789
November 2011
|
Okay in my game, I have background music, currently it is in: 'al_play_sample(bg_music, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL);' but when I pause the game I want the sample to pause. How could I do that? Or do I have to make a stream! and If so how do I make a stream? |
larzconwell
Member #13,789
November 2011
|
Okay here's how its working if (bg_music_on == false) { When I press enter it runs through that if..else, bg_music_on is false at first. When I press enter again and it starts the sample, it restarts it. How do I make it pause? or turn the gain down |
Matthew Leverton
Supreme Loser
January 1999
![]() |
The simple API that you are using doesn't support that sort of thing. If you want to micro-manage, you'll need to load sample data and create a sample instance and use al_set_sample_instance_playing(). |
SiegeLord
Member #7,827
October 2006
![]() |
In this case you're better of not using the simple audio API, but using the more advanced API. You'd do something like this: /* Level initialization */ ALLEGRO_SAMPLE_INSTANCE* bg_music_instance = al_create_sample_instance(bg_music); al_attach_sample_instance_to_mixer(bg_music_instance, al_get_default_mixer()); al_set_sample_instance_playmode(bg_music_instance, ALLEGRO_PLAYMODE_LOOP); al_play_sample_instance(bg_music_instance); /* Game paused */ al_set_sample_instance_playing(bg_music_instance, false); /* Game un-paused */ al_set_sample_instance_playing(bg_music_instance, true);
"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
larzconwell
Member #13,789
November 2011
|
That works great! Thanks!! Just it still, restarts the song. |
SiegeLord
Member #7,827
October 2006
![]() |
It does? That's odd. Well, then you can save the spot you're in the music before you stop it using al_get_sample_instance_position and then do al_set_sample_instance_position after you restart it. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
larzconwell
Member #13,789
November 2011
|
Instead of using 'al_set_sample_instance_playing' I used 'al_set_sample_instance_gain', It works good enough! |
|