Destroy XAudio2 at Runtime

This forum is currently in read-only mode.
From the Asset Store
Antisuspend Plugin
$7.20 USD
20% off
Antisuspend Plugin for Construct 3 prevents the runtime from getting suspended.
  • I have a dilemma. I created an XAudio2 object in my second layout (a level) and made it Global. I have a ton of events set up for music and sound effect control throughout that level. I then went to my first layout (the main menu) and started adding sound effect events there as well. However they didn't play on the Main Menu, presumably because the XAudio2 object hadn't been loaded yet, since it was a part of the second layout - they only played on the Main Menu if I started a new game to get to the Level layout, then from that level returned to the main menu (with the XAudio2 object now loaded).

    To get around this issue I created an event where an XAudio2 object would be created at the start of the Main Menu layout. Problem solved! The Main Menu now has sound effects right from the start! But... when I now start a new game there are TWO XAudio2 objects playing music and sound effects in the Level layout, leading to distortions and possibly even reduced performance.

    Is there a way to destroy XAudio2 objects at runtime? Because I can't find the option anywhere. I imagine if I can destroy the XAudio2 object from the Main Menu just before the Level layout is loaded, the duplicate sound effects and music issues will be resolved.

    The only other solution I can think of is to delete the global XAudio2 object from the Level layout (which would delete all of my sound effect and music events <img src="smileys/smiley6.gif" border="0" align="middle" />) and start again, creating the base XAudio2 object on the Main Menu this time around. Obviously, I'd reeeeaaaaally like to not do that.

    Thanks for reading. I hope someone can think of something <img src="smileys/smiley12.gif" border="0" align="middle" />

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 1. You could add it to a container with an object you can destroy.

    2. You could add the attribute "destroy on startup" to the object and just create it at runtime.

    3. You could copy/paste XAudio2 from the level to the menu layout, Then delete XAudio2 from the level. The events should remain intact, because you still have one instance.

  • Thank you R0J0! I tried the third option first, and it worked perfectly <img src="smileys/smiley1.gif" border="0" align="middle" />

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