Music restarting.

Get help using Construct 2

Post » Tue Apr 23, 2013 5:20 pm

I just wonder about something. Im making a game and the music start playing when the game starts because it is on the "On start of layout" event. But when I die, and press play again. That restarts the layout so the music restarts. How do I fix that? (Music restarting when im pressing play again).
Thanks for your help.

-Regards HavardFB
B
11
S
3
G
2
Posts: 15
Reputation: 2,399

Post » Tue Apr 23, 2013 5:57 pm

Use a global variable to indicate whether you've already started playing the music, and only play it on startup if it's not already playing.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Tue Apr 23, 2013 5:58 pm

You have set the music to start on the start of layout, if you restart the layout it fires start of layout again. So you coded it to do exactly what it is doing. Ashley's solution should get you the rest of the way there.BluePhaze2013-04-23 17:59:26
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,428

Post » Tue Apr 23, 2013 7:22 pm

I had the same issue. I added another event to stop playing music and then start playing music on start of layout.

Works for now. Not sure how the global variable thing works.
B
50
S
14
G
12
Posts: 813
Reputation: 16,764

Post » Tue Apr 23, 2013 7:47 pm

I think you could also use "Audio>Is tag playing", maybe, and if it's not playing, then start it. I might be wrong about that though...
B
9
S
3
G
4
Posts: 63
Reputation: 3,083

Post » Wed Apr 24, 2013 6:14 pm

Thanks for your replies, but I dont understand the global variable thing. And what if im switching layout without stopping music, when I switch back the music will restart. How do I fix that?
B
11
S
3
G
2
Posts: 15
Reputation: 2,399

Post » Wed Apr 24, 2013 7:47 pm

@bearboxmedia
www.bearboxmedia.com

Nintendo Wii U Developer using Construct 2
B
68
S
8
G
6
Posts: 930
Reputation: 9,358


Return to How do I....?

Who is online

Users browsing this forum: Colorfish and 28 guests