This site requires JavaScript, please enable it in your browser!
Greenfoot back
OfficerRiot
OfficerRiot wrote ...

2018/4/24

Trying to change Volume of background music

OfficerRiot OfficerRiot

2018/4/24

#
I'm having problems I'm new to java and stuff but anyway I have a title screen world and that's where the music plays I also have an options menu with volume which is a totally different world. I know the code of most of it what I'm stuck is when I try to change the volume from the actor it says cannot find symbol. I'm really stuck on this I looked really hard on the internet but could not find anything.
OfficerRiot OfficerRiot

2018/4/24

#
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class TitleScreen here. * * @author (your name) * @version (a version number or a date) */ public class TitleScreen extends World { GreenfootSound backgroundMusic = new GreenfootSound("TitleScreenMusic.mp3"); /** * Constructor for objects of class TitleScreen. * */ public TitleScreen() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(700, 700, 1); prepare(); } public void prepare() { ScreenText screentext = new ScreenText(); addObject(screentext, 350, 350); Start start = new Start(); addObject(start, 550, 180); Options options = new Options(); addObject(options, 548, 270); Quit quit = new Quit(); addObject(quit, 548, 350); } public void started() { backgroundMusic.playLoop(); } public void stopped() { backgroundMusic.stop(); } public void act() { } } This is the code for my title screen and this is the code where im trying to change the volume import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class VolumeOff here. * * @author (your name) * @version (a version number or a date) */ public class VolumeOff extends Actor { /** * Act - do whatever the VolumeOff wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if (Greenfoot.mouseClicked(this)) backgroundMusic.setVolume(0); } }
danpost danpost

2018/4/24

#
OfficerRiot wrote...
I have a title screen world and that's where the music plays I also have an options menu with volume which is a totally different world. I know the code of most of it what I'm stuck is when I try to change the volume from the actor it says cannot find symbol.
Please take example from my BgMusic Actor Class Demo wArcBar Class scenario.
OfficerRiot OfficerRiot

2018/4/24

#
danpost wrote...
OfficerRiot wrote...
I have a title screen world and that's where the music plays I also have an options menu with volume which is a totally different world. I know the code of most of it what I'm stuck is when I try to change the volume from the actor it says cannot find symbol.
Please take example from my BgMusic Actor Class Demo wArcBar Class scenario.
ok, I looked at it but I could not find anything that would work.
danpost danpost

2018/4/25

#
In the VolumeOff class, use:
TitleScreen.backgroundMusic.setVolume(0);
In TitleScreen class, change:
// this
GreenfootSound backgroundMusic = new GreenfootSound("TitleScreenMusic.mp3");

// to this
public static GreenfootSound backgroundMusic = new GreenfootSound("TitleScreenMusic.mp3");
You need to login to post a reply.