Jump to content


Photo

Playing Sounds Once


  • Please log in to reply
9 replies to this topic

#1 Taizen Chisou

Taizen Chisou

    Deus Ignis,

  • GMC Member
  • 250 posts
  • Version:GM8

Posted 14 September 2011 - 12:58 AM

I cannot for the life of me figure this out.

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?
  • 0

#2 thegame

thegame

    Flying Penguin

  • GMC Member
  • 1407 posts
  • Version:GM:Studio

Posted 14 September 2011 - 01:25 AM

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)
  • 0

#3 kremling

kremling

    GMC Member

  • GMC Member
  • 146 posts

Posted 14 September 2011 - 01:26 AM

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();
}

Edited by kremling, 14 September 2011 - 01:30 AM.

  • 0

#4 Taizen Chisou

Taizen Chisou

    Deus Ignis,

  • GMC Member
  • 250 posts
  • Version:GM8

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.
  • 0

#5 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9260 posts
  • Version:Unknown

Posted 16 September 2011 - 12:00 AM

When the first bullet plays the sound, have it set a global variable (like "dontSound") to true. Set a very short alarm (a few frames, just to give the sound a chance to start playing) and set global.dontSound back to false. If that variable is true, the other bullets shouldn't play their sounds.

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
  • 0

#6 Taizen Chisou

Taizen Chisou

    Deus Ignis,

  • GMC Member
  • 250 posts
  • Version:GM8

Posted 16 September 2011 - 10:11 PM

Wouldn't that result in an 80-times bullet sound playing, and then not repeating until at least 12 frames, where the 80-times bullet sound will play again? :/

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.

  • 0

#7 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9260 posts
  • Version:Unknown

Posted 16 September 2011 - 10:19 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 :lol: ). 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

Edited by IceMetalPunk, 16 September 2011 - 10:21 PM.

  • 0

#8 Katuko

Katuko

    GMC Member

  • GMC Member
  • 4886 posts

Posted 16 September 2011 - 10:24 PM

Edit: Wrong topic.

Edited by Katuko, 16 September 2011 - 10:24 PM.

  • 0

#9 Taizen Chisou

Taizen Chisou

    Deus Ignis,

  • GMC Member
  • 250 posts
  • Version:GM8

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 :lol: ). 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...?
  • 0

#10 kremling

kremling

    GMC Member

  • GMC Member
  • 146 posts

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users