Multiple Background Music

This forum is currently in read-only mode.
From the Asset Store
Be quick and choose the right answer for the shown equation.
  • I can not seem to figure this one out. I currently have:

    + System: Start of layout

    -> XAudio2: Autoplay resource "Skillet - Hero (instrumental).wav" (Loop)

    How can I go about having multiple music clips playing one after another, but then looping back to the beginning of the play list? Is it easier to just combine all the clips into one, using my audio editor, to stick with just one background WAV for Construct?


  • I think you would be better just having a single WAV, or combining them all together. I'm not sure if there is any conditions available that deal with music files ending/starting, but I could be wrong.

  • When using 'autoplay resource' you're using the sound part of XAudio2, not the music part. That has a few advantages. While playing music does not allow you to get informations about the music, you have control over sounds that are playing:

    Get length

    Get position

    Just test the second against the first. There is only one thing to keep in mind, and that is the frames at which the game runs. If it runs with 60 fps you won't be able to catch the exact end of the song. It is better to just test if the position is greater than a certain distance from the end.

    position >= length - 0.25 (or any other number that works with your framerate)

    To get the channel number of the sound you can use 'Get last channel autoplayed', but it would be much easier to load the resource to a specific channel. Then use 'Set reserved' to protect this channel.

    You can use an array for the file names of the wav files and a global variable that increases with every sound played and corresponds to the index of the next wav file name to load. But you would then need to load them from a folder, because if I remember right there's an issue that prevents using strings for the resources.

  • Here is an example to the explanations above:

  • Thanks, palies. Will try it all out and report back.

  • Still looking at this. Although the events still a bit away for me to fully understand, I think I have the idea how it all works.

  • Is it more efficient to keep music as files to be pulled from a directory:

    + File: For each file in AppPath & "audio"

    ...and keep sound effects as resources:

    -> XAudio2: Autoplay resource "Skillet - Hero (instrumental).wav" (Loop)

  • To continue this, I have just recently made my first EXE in months and realized that the background music is not included, being set for files instead of being resources.

    + System: Is global variable 'currentfile' Less than global('fileindex')

    -> System: Add 1 to global variable 'currentfile'

    -> XAudio2: Load file AppPath & "music\" & filenames (global('currentfile')) to channel 1 (No loop)

    -> XAudio2: Play channel 1

    -> tCurrent: Set text to filenames (global('currentfile'))

    + System: Else

    -> System: Set global variable 'currentfile' to 1

    -> XAudio2: Load file AppPath & "music\" & filenames (global('currentfile')) to channel 1 (No loop)

    -> XAudio2: Play channel 1

    -> tCurrent: Set text to filenames (global('currentfile'))

    Is it possible to set this up so they can be set as resources and therefore be included in the EXE package?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I know this is kinda an old thread, but this is the issue that I am facing.

    The previous post refers to:

    -> XAudio2: Load file AppPath & "music\" & filenames (global('currentfile')) to channel 1 (No loop)

    This allows the song name to be stored in a varaible.

    But how do you actually put that line above into construct?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)