This site requires JavaScript, please enable it in your browser!
Greenfoot back
MyN@m31$J3ff2022
MyN@m31$J3ff2022 wrote ...

2022/10/26

Changing Volume in a game?

MyN@m31$J3ff2022 MyN@m31$J3ff2022

2022/10/26

#
I have a question in regards to an earlier post by OfficerRiot about changing the Volume of background Music. I have music that will play in the background of a pong game I've made, but it's so loud that you could barely hear to soundfx that I've added to the game. Is there any way to take a downloaded music track and make it quieter using Greenfoot coding?
private GreenfootSound bgMusic = new GreenfootSound("Heartache.mp3");

public void act()
    {
        if(!isMusicPlaying)
        {
            bgMusic.playLoop();
            isMusicPlaying = true;
        }
    }
    public void stopped()
    {
        bgMusic.stop();
        isMusicPlaying = false;
    }
The first line of code was me establishing the file to play in the background of my game, and the next two methods listed in the code show how I am initiating the music to play and how I'm telling it to stop, however, I don't quite know how I'm meant to make it's volume quieter, if that's even possible.
MyN@m31$J3ff2022 MyN@m31$J3ff2022

2022/10/26

#
public MyWorld()
    {  
        super(695, 564, 1);
        
        Paddle leftPaddle = new Paddle("WS");
        Paddle rightPaddle = new Paddle("ARROWS");
        
        addObject (leftPaddle,30,300);
        addObject (rightPaddle,665,300);
        addObject (new Ball(bgMusic), getWidth()/2, getHeight()/2);
Sorry. Forgot that there was coding in my MyWorld constructor class that dealt with starting the background music. It's the coding for adding the Ball() to the screen.
danpost danpost

2022/10/26

#
MyN@m31$J3ff2022 wrote...
Is there any way to take a downloaded music track and make it quieter using Greenfoot coding?
There is a setVolume(int) method in the GreenfootSound class (where the int can be between 0 (muted) to 100 (loudest).
danpost danpost

2022/10/26

#
MyN@m31$J3ff2022 wrote...
there was coding in my MyWorld constructor class that dealt with starting the background music. It's the coding for adding the Ball() to the screen.
Question: why do you send a reference to the music to your new balls?
You need to login to post a reply.