How do I Stop An Instance of A Looping Sound And Not All Instances of That Sound?

0 favourites
  • 6 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • Hello,

    I have multiple instances of the same enemy in a layout. When they're alive, they play a looping "buzzing" sound. As the enemies are spawning in, a new "buzzing" sound plays like I want it to.

    When one of them is destroyed, I want to stop the buzzing sound of the one that was killed. What ends up happening is that the "buzzing" sound stops completely for all instances, because my only option for an action in my event seems to be "stop buzz."

    Any thoughts on how I can make this work?

    Tagged:

  • You will need to make use of tags, and one way to do it is to say 'enemy on created' 'play audio at object enemy' using tag ""&enemy.UID, this will give it a unique name related to the enemy. Then you can also say 'enemy on destroyed' stop tag "&enemy.UID

  • That worked. Thank you very much lionz!

  • Although it does work as intended with a few instances, it seems to have trouble after 6 or 8 instances of the enemy. If I happen to kill the enemies very quickly or all at once, the sounds persist for a few seconds after they're destroyed. But other times one or two instances of the sound continue playing forever after the last enemy is destroyed.

    It definitely works, to a point. Will have to investigate this more.

  • Alright here's what I did wrong. What lionz said was the correct way of doing it. My problem came with the conditions I had to stop the sound.

    My enemies had a death animation before the object was destroyed so I needed the sound to stop when they stopped moving. I had "is not moving" as the condition for the action "stop sound."

    I made the condition "on destroyed" to test and it worked as intended whether I had 2 or 20 instances of the enemy. Even though the sound plays during their death animation, it properly ends the sounds as they should. So I made a separate event that had the original condition of not moving as well, and no matter how many instances I had, it stopped the sounds as it should, while also stopping it when the enemies had their death animation.

    Hope someone can learn from my mistakes :)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • That's good, you will need these kind of investigative debugging skills when building a game :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)