Playing Sounds Once
#1
Posted 14 September 2011 - 12:58 AM
Bullet hell games spawn lots of bullets.
I have a code where 80 of the same bullet appear at the same time.
They all play a PSHKPCHKKT blasting noise on creation.
As you might imagine, it really gunks up the BGM and sounds awful to boot.
How do I avoid this?
#2
Posted 14 September 2011 - 01:25 AM
if(!sound_isplaying(PSHKPCHKKT)){
sound_play(PSHKPCHKKT);
}Only once will the sound be played (hopefully)
#3
Posted 14 September 2011 - 01:26 AM
Player Step Event
if (keyboard_check_pressed("key to shoot bullets") == true && instance_number(objBulletController) == 0){
i = instance_create(x,y,objBulletController);
}
//objBulletController code Create Event sound_loop( "bullet sound" );
Step Event
if (instance_number("object bullet") == 0 || keyboard_check( "key used to shoot bullets") == false){
sound_stop( "bullet sound" );
instance_destroy();
}
Edited by kremling, 14 September 2011 - 01:30 AM.
#4
Posted 15 September 2011 - 11:56 PM
In the creation event(or wherever the sound is played from) use
if(!sound_isplaying(PSHKPCHKKT)){ sound_play(PSHKPCHKKT); }
Only once will the sound be played (hopefully)
This does not work, mainly because there are eighty prompts to play a sound at the same frame.
Maybe you could create a bullet controller. Create an object and name it something like, objBulletController. Everytime you press the shooting key, create the bullet control object. Make sure however, you do something like...
Player Step Event if (keyboard_check_pressed("key to shoot bullets") == true && instance_number(objBulletController) == 0){ i = instance_create(x,y,objBulletController); }//objBulletController code Create Event sound_loop( "bullet sound" );Step Event if (instance_number("object bullet") == 0 || keyboard_check( "key used to shoot bullets") == false){ sound_stop( "bullet sound" ); instance_destroy(); }
And this isn't really what I was looking for :/
Game Maker will play a sound 80 times at the same time, which I'm trying to cut down to one.
#5
Posted 16 September 2011 - 12:00 AM
So, like this:
/* CREATE event */
if (!global.dontSound && !sound_isplaying(bullet_snd)) {
sound_play(bullet_snd);
global.dontSound=true;
alarm[0]=room_speed/5;
}
/* Alarm[0] event */
global.dontSound=false;-IMP
#6
Posted 16 September 2011 - 10:11 PM
Or... not, because it uses a global variable...?
But if that all happens at the same time, then it doesn't matter, right?
I ask this, because I have too many different variations of bullets
Edited by gamefreek2, 16 September 2011 - 10:13 PM.
#7
Posted 16 September 2011 - 10:19 PM
By the way, the only reason the alarm[0] thing is in there is so that instances created later can still play the sound. This way it only stops other instances created at the same time from playing the sound. Also, there's a slight delay between the time you call sound_play() and when sound_isplaying() starts returning true, so this small delay before setting the global variable back to false also helps avoid issues with that.
-IMP
Edited by IceMetalPunk, 16 September 2011 - 10:21 PM.
#8
Posted 16 September 2011 - 10:24 PM
Edited by Katuko, 16 September 2011 - 10:24 PM.
#9
Posted 17 September 2011 - 03:21 PM
There's no such thing as any computer instruction happening at the same time as another (unless you're talking about threads...but GM is not threaded...without the Threads DLL...which I assume you're not using
). The CREATE events will execute sequentially for each instance, in the order they were created (in the case of instances placed in the Room Editor, this is the same as in order of instance ID). So when one plays the sound, it sets the global variable, and the others will see that change by the time their CREATE event triggers, preventing multiple instances from playing the same sound.
By the way, the only reason the alarm[0] thing is in there is so that instances created later can still play the sound. This way it only stops other instances created at the same time from playing the sound. Also, there's a slight delay between the time you call sound_play() and when sound_isplaying() starts returning true, so this small delay before setting the global variable back to false also helps avoid issues with that.
-IMP
I'll try it, thank you.
But it'll take a long time to implement D:
As for the alarm business, do you know if setting it to 1 will allow bullets of the next step to sound as well?
Or do alarms take place after the create...?
#10
Posted 17 September 2011 - 05:40 PM
In objBulletControl...
//Create Event
sound_loop("bullet sound");
//Step Event
if (keyboard_check(vk_control) == false){
sound_stop("bullet sound");
instance_destroy();
}
In the object that is shooting the bullets...
//Step Event
if (keyboard_check(vk_control) == true){
if (instance_number(objBulletControl) == 0){
i = instance_create(x,y,objBulletControl);
}
if (instance_number(objBulletControl) == 1){
i = instance_create(x,y,objBullet);
}
}
In the bullet object...
//Outside the room
instance_destroy();
This code does work. Try it. : )
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











