public class Background extends World
{
/**
* Constructor for objects of class MyWorld.
*
*/
static final Color TRANS = new Color(0, 0, 0, 0);
Actor btn01,btn02,btn03;
public Background()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(900, 600, 1);
addObject(btn01 = getNewButton("BUTTON 01"),200,100);
addObject(btn02 = getNewButton("BUTTON 02"),200,150);
addObject(btn03 = getNewButton("BUTTON 03"),200,200);
}
public void act()
{
if(Greenfoot.mouseClicked(btn01))
Greenfoot.playSound("01 - Moonlight.waw");
if(Greenfoot.mouseClicked(btn02))
Greenfoot.playSound("02 - Dangerous Woman.waw");
if(Greenfoot.mouseClicked(btn03))
Greenfoot.playSound("03 - Be Alright.waw");
}
public Actor getNewButton(String caption)
{
GreenfootImage base = new GreenfootImage(400,230);
base.setColor(Color.BLUE);
base.fillRect(100,100,200,30);
GreenfootImage text = new GreenfootImage(caption, 24, Color.BLACK, TRANS);
base.drawImage(text, 200-text.getWidth()/2, 115-text.getHeight()/2);
base.setTransparency(128);
Actor button = new Actor()
{
};
button.setImage(base);
return button;
}
}
