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

2012/6/10

Background music

Jesse_Orange Jesse_Orange

2012/6/10

#
I gave background music with the functions to play and pause but can i control this from an actor?
limefortheworld limefortheworld

2012/6/10

#
Yes. Make a public variable (or give it public functions to manipulate it) For an example,
private GreenfootSound bgm = new GreenfootSound("insert file name here");

//function to make bgm play
public void playBGM()
{
    bgm.play();
}

public void stopBGM()
{
    bgm.stop();
}
Once you have that, go to the actor you wish to implement the control on
(World class name) world;

//This registers the world, so that you can use the world's function
public void addedToWorld(World w)
{
    //Typecasting, replace World class name with whatever the name of your world class. for example, put AynRandSucks if you named the world AynRandSucks
    world = (World class name) w;
}

//and then if you wish to manipulate the bgm, simply use world.playBGM() or whatever function name you have given to achieve your goal.
You need to login to post a reply.