How to set volumn slider in phaser js?

Viewed 61

How to set volumn slider in phaser js? like this showing below image and also tell me how to set defult value of the slider if i change screen slider value become zero.

enter image description here

 var print2;
    this.rexUI.add.slider({
            x: 400,
            y: 230,
            width: 200,
            height: 30,
            orientation: 'x',

            track: this.rexUI.add.roundRectangle(0, 0, 0, 0, 10, COLOR_DARK),
            indicator: this.rexUI.add.roundRectangle(0, 0, 0, 0, 10, COLOR_PRIMARY),
            thumb: this.rexUI.add.roundRectangle(0, 0, 0, 0, 10, COLOR_PRIMARY),

            input: 'click', // 'drag'|'click'
            easeValue: { duration: 250 },

            valuechangeCallback: function(value) {
                value *= 10
                value = Math.floor(value * 10)
                print2 = value;

                console.log(print2);
            },

        })
        .layout();
1 Answers

Well for setting the default - value of the slider, you just need to add the value property.

let slider = this.rexUI.add.slider({
    ...
    value: .5 // default vaule
    ...
});

to set the slider value later, just set slider.value = .5;

Here the link to the documentation

Setting the volume for Phaser Audio:

let sound = this.sound.add('sound');
sound.play({loop: true });
...
let slider = this.rexUI.add.slider({
    ...
    valuechangeCallback: function(value){
        sound.volume = value; // set volume between 0 - 1
    }
    ...
});

Here a link to an offical demo: link to demo

Related