Multi-Resolution Game Development With GameBuilder Studio Check it out!
NEW Version 0.9.7 has arrived! New Blazing Fast Particle Engine & More Game Actions. Check it out
One Button to toggle Background Music Off/On
  • To have one UI(user interface) button to turn off/on your background music

    Here is one way to do this.

    STEP 1)
    On the right editor panel at the top click Globals.
    In the Data/Properties Container, click Add.
    You will see a NewProperty bar added, you can name it something like: soundsPlaying and set it as an integer to 1. You are done here.

    STEP 2)
    Just outside your view area of your game add a generic object(the square) and remove the spatial by first adding a basic spatial to it,  select renderer, and then remove the default spatial from it(click the red X button).

    *You may already have done something like this and made it your Global Game State which has the logic for your game’s states in it such as GAME_STARTED, GAME_RUNNING, GAME_PAUSED, GAME_OVER.
    You can add the following sound control to this or not, or just set up a new generic object.

    Add a Background Sound Player and name it Music for example.
    Then select your music track and check Auto Start.

    Now Add a Rules Map component, name it something like MusicToggle or something you'll remember what it is.
    Check for
    select Property and enter
    #Globals.Data.soundsPlaying = 0

    Trigger Action:
    select Call Method and enter

    Otherwise Trigger Action:
    Call Method and enter

    STEP 3)
    On your button on the game screen that tells a player it has something to do with music or sound, like music notes, add a Rules Map component and name it something like Logic_TouchDown.
    Check for
    select Event Captured
    Touch is Down, and check 'On Entity’

    Trigger Action:
    select Change Property and enter
    #Globals.Data.soundsPlaying = Expression, enter this:    ( Globals.Data.soundsPlaying + 1) % 2

    That's it. You're done.

    *Note, a nice effect to add to the Logic_TouchDown Rules Component is to have a scale down effect when the button is touched.
    To do this add to the Trigger Action:
    another Change Property
    @Renderer.scale =Type Point x 0.9 y 0.9

    Otherwise Trigger Action:
    Change Property
    @Renderer.scale =Type Point x 1 y 1

  • 2 Comments sorted by
  • @BenFromOregon, this should be simplified now with the toggle property action.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion