Forums

OverviewV-Play 1 Support › Background music help please

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #7246

    Jeff

    I added this to level.qml in flappy bird

      BackgroundMusic {
        id: backgroundMusic
        source: "../audio/music.mp3"
        // autoPlay: true - this is set by default
      }

    and it plays great but im not sure where to put an imagebutton so I can call the states for pause and play. I tried to do it in gamescene.qml but no luck..i don’t even know if Im doing the right code. thanks for the help all

    #7254

    Christian
    V-Play Team
    #7255

    Jeff

    hey, I looked at the examples but I still cannot find where they show how to mute the music with a button. I have added the above code to level.qml and it works but I need to add an icon on the screen to pause the music and to play it when clicked again. are you able to give me an example where to put the codes…is it in the gamescene.qml? do I have to create new fucntions for the backgroundmusic code? thanks

    #7256

    Alex
    V-Play Team

    Hi,

    the code could look like this:

    ImageButton {
        onClicked: {
          //the settings.musicEnabled flag enables/disables the background music, and also stores this in the database, so the music stays enabled/disabled on the next app start
          settings.musicEnabled = !settings.musicEnabled
        }
        // change the source to display different images in case the music is enabled or disabled
        source: settings.musicEnabled ? "music_on.png" : "music_off.png"
      }

    Of course you will have to add the images for the button (in my example music_on.png and music_off.png) to the spritesheet.

    Hope this helps.
    Cheers,
    Alex

    • This reply was modified 4 years, 3 months ago by  Alex.
    #7258

    Jeff

    hey thank you so much…the code works under menu.qml but I cannot get it to work under gamescene…any ideas?

    #7259

    Jeff

    I got it, I put it in the main.qml instead. thanks

Viewing 6 posts - 1 through 6 (of 6 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support