Music keeps starting again on every frame
-
I'm trying to make a piece of music play but it is restarting on every frame and it just sounds like someone is firing a machine gun. Another sound effect plays as expected whem my player collides with something. What am I doing wrong?
-
@daneeboy sounds like it's constantly trying to play the sound because what ever is triggering it keeps triggering. Try to find something that it Will trigger with and won't until you need it again.
If it's a piece of music you can set it outside the main loop.
-
@waldron I will try putting the piece of music outside my main loop. Thank you 👍
-
You can put it outside of the loop and it'll work fine but won't start again once it's finished. What I used to do is this:-
I pick a channel to play the music on (let's say channel 0) and then add this inside my main loop
if !getchannelstatus(0) then playaudio(0,music,2,0.5,1,0) endif
What that does is check channel 0 and if the music is playing it leaves it but if there is no music playing then it starts the music again. Which means the music will play perfectly and loop.
-
Alternative: you can place the call once outside the main loop, but with -1 passed to the last parameter to repeat indefinitely.
-
You can also set a variable as a ‘flag’, and have something like this:
Int musicHasStarted = false //outside the main loop While true loop //start of main loop If musicHasStarted == false then //Playaudio command or whatever musicHasStarted = true Endif Repeat //end of main loop
Then it’ll only start it once. Hope that’s understandable
-
I will play around with toxibunnys and stevezx81 explanation because maybe I could use these methods to change music on entering different areas or rooms in my game. Thanks.