Hey so ive been scouring the web for a while now and i cant seem to find the answer to this problem.
I ahve multiple worlds. one of which is a start screen that loads when you enter the game. This is all fine. however from the start screen you can play or you can go tot he help menu. when you go to the help menu and then return to the start screen world, the music that is set to play simply plays again? My assumption is that the instance of title.mp3 that was originally created is now no longer accessible from the new world instance of the start screen and that is why the (if not playing then play" method isnt working here as it doesnt recognise the first instance of the sound so then it just plays a second one. How can i make it recognise that that first instance is still there and therefore not play a new one?
thats my start screen code. the problem is as described above. when leaving and returning to this screen, a new instance of the audio is created.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Start here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Start extends World
{
GreenfootSound title = new GreenfootSound("title.mp3");
/**
* Constructor for objects of class Start.
*
*/
public Start()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(800, 600, 1);
prepare();
if( !title.isPlaying())
{
title.setVolume(50);
title.play();
}
}
/**
* Prepare the world for the start of the program. That is: create the initial
* objects and add them to the world.
*/
private void prepare()
{
startscreen startscreen = new startscreen();
addObject(startscreen, 418, 331);
startscreen.setLocation(400, 300);
StartButton startbutton = new StartButton();
addObject(startbutton, 238, 376);
startbutton.setLocation(244, 338);
howToPlay howtoplay = new howToPlay();
addObject(howtoplay, 252, 480);
howtoplay.setLocation(246, 477);
}
public void act()
{
}
}

