Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Music keeps starting again on every frame

    Help
    5
    7
    461
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • DANEEBOY
      DANEEBOY last edited by

      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?

      waldron 1 Reply Last reply Reply Quote 0
      • waldron
        waldron F @DANEEBOY last edited by waldron

        @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.

        DANEEBOY 1 Reply Last reply Reply Quote 2
        • DANEEBOY
          DANEEBOY @waldron last edited by

          @waldron I will try putting the piece of music outside my main loop. Thank you 👍

          1 Reply Last reply Reply Quote 0
          • SteveZX81
            SteveZX81 F last edited by SteveZX81

            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.

            1 Reply Last reply Reply Quote 5
            • D
              DaddyJDM last edited by

              Alternative: you can place the call once outside the main loop, but with -1 passed to the last parameter to repeat indefinitely.

              1 Reply Last reply Reply Quote 4
              • PickleCatStars
                PickleCatStars F last edited by PickleCatStars

                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

                1 Reply Last reply Reply Quote 3
                • DANEEBOY
                  DANEEBOY last edited by

                  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.

                  1 Reply Last reply Reply Quote 2
                  • First post
                    Last post