Continuing same music through multiple layouts

For questions about using Classic.

Post » Mon Feb 02, 2009 1:44 am

I have a couple layouts I want to use, but I want to use the same music throughout, without restarting it. So I was wondering if it was possible to continue the music playing through multiple layouts without stopping?
:?:
B
2
G
3
Posts: 24
Reputation: 898

Post » Mon Feb 02, 2009 1:48 am

Check the "Global" box under the common properties for the XAudio2 object. And if you're not using the XAudio2 object, you definitely should be.
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

Post » Mon Feb 02, 2009 2:11 am

Thanks. And yes, I am using the XAudio2 object, since I know of no other =)


Well, I have another problem now. The music starts at the menu, and at the menu there are several options. The menu layout has this in it's event sheet-

[code:1xsj263p]Start of Layout-
XAudio2- Play music "asdf.mp3"
XAudio2- Loop music
[/code:1xsj263p]

So when I enter a sub-item of the menu, I go to another layout. In that layout, there is a back button- so basically, when I return to the menu, the code runs through again, and thus, the music starts playing from the top. Can I make this not happen, perhaps by putting the play music code elsewhere? Or prevent it from running through twice?
B
2
G
3
Posts: 24
Reputation: 898

Post » Mon Feb 02, 2009 2:58 am

Perhaps try something like this:

First, create a global variable called "playmusic" and set it's default value to 1. Then put this code in the first layout(this is all in one event):
[code:3k4mmjin]
+Start of Layout
+Is global variable 'playmusic' equal to 1
-XAudio2- Play music "asdf.mp3"
-XAudio2- Loop music
-Set global variable 'playmusic' to 0
[/code:3k4mmjin]

The global variable acts like a flag to determine if the music can play or not. Hope that helps. :)
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

Post » Mon Feb 02, 2009 3:06 am

Thanks for the reply. However, is +Is global variable 'playmusic' equal to 1 a sub-event of Start of Layout? If it is, I can't find it for some reason. I looked under system and could not find a variable thingymagigy. Could you perhaps quickly make a .cap?
B
2
G
3
Posts: 24
Reputation: 898

Post » Mon Feb 02, 2009 5:17 am

You define your global variables in the Application properties. Then you can compare them in a condition with "System->Compare global variable."
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Mon Feb 02, 2009 8:22 am

Added this one to the FAQ because it seems to come up a lot.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Mon Feb 02, 2009 11:31 pm

Thanks to linkman2004 for the code (it works, trying to figure out how it works so I can use it for other purposes =) ) and deadeye for the help on where to find it, and of course to Ashley for the program in the first place. Glad it got added to the FAQ. Thanks all! :D
B
2
G
3
Posts: 24
Reputation: 898


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 7 guests