Destroy XAudio2 at Runtime

For questions about using Classic.

Post » Fri Dec 07, 2012 1:18 pm

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 ) 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
B
15
S
7
G
7
Posts: 250
Reputation: 5,298

Post » Fri Dec 07, 2012 3:40 pm

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.
B
79
S
24
G
54
Posts: 4,750
Reputation: 40,763

Post » Fri Dec 07, 2012 4:01 pm

Thank you R0J0! I tried the third option first, and it worked perfectly
B
15
S
7
G
7
Posts: 250
Reputation: 5,298


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests