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

2012/9/9

Sound Help

Stephon231 Stephon231

2012/9/9

#
i am trying to get background music for my game but when i press run it starts and then i prees pause and it doesn't stop playing it just keeps going until it is over
danpost danpost

2012/9/9

#
If you have an instance GreenfootSound field in the world class
GreenfootSound bgMusic = new GreenfootSound("trackName.mp3");
you can add the following method
public void stopped()
{
    bgMusic.stop();
}
Of course, replace "trackName.mp3" with the String name of the music file you are using.
Stephon231 Stephon231

2012/9/9

#
im new to greenfoot so were would i place the instance
danpost danpost

2012/9/9

#
The normal layout of a class would be -imports -class declaration -instance fields -constructors -methods Sample:
import greenfoot.*

public class MyWorld extends World
{
    GreenfootSound bgMusic = new GreenfootSound("trackName.mp3");
    // other fields

    public MyWorld()
    {
        bgMusic.play();
        // other possible code
    }

    public void stopped()
    {
        bgMusic.stop();
    }

    public void act()
    {
        // code
    }

    // other methods
}
Stephon231 Stephon231

2012/9/10

#
is there a way to have an actor stop the music
danpost danpost

2012/9/10

#
Sure,, you just need to get a reference to your world.
((MyWorld) getWorld()).bgMusic.stop();
You need to login to post a reply.