So, how would I go about making a button that can turn off the background music?
For my game of Breakout I already have music playing in the background when you press 'Run'.
I have no idea what the code would be for it etc. xD
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
import java.awt.Color;
import javax.swing.*;
public class Button extends Actor
{
private int funktion;
private String name;
private boolean funktionAusgefuehrt;
public void setImages(GreenfootImage image)
{
setImage(image);
}
public Button(int width, int height, String pName, int pFunktion, GreenfootImage pImage)
{
name = pName;
GreenfootImage image = pImage;
image.drawString(pName, width, height);
funktion = pFunktion;
setImage(image);
}
public void act()
{
mausUeberButton();
anklicken();
}
public void mausUeberButton()
{
MouseInfo meineMaus = Greenfoot.getMouseInfo();
if(meineMaus!=null)
{
if(meineMaus.getActor() == this && !funktionAusgefuehrt)
{
}
if(meineMaus.getActor() != this && funktionAusgefuehrt)
{
funktionAusgefuehrt = false;
}
}
}
public void anklicken()
{
MouseInfo meineMaus = Greenfoot.getMouseInfo();
if(meineMaus != null)
{
if(funktion==0 && Greenfoot.mouseClicked(this))
{
World world = new YourWorld();
world.yourMusic.stop();
}
}
}
}Button endles = new Button(width, height, "", 0, imageOfButton);