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

2024/5/3

i need help, why sound keep playing when i clicked Play.class?

Newrestar Newrestar

2024/5/3

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Music1 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Music1 extends Actor
{
    GreenfootSound myHomesound = new GreenfootSound("menu.mp3");
    boolean firstTurn = true;
    /**
     * Act - do whatever the Music1 wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()
    {
     if(firstTurn)
     {
       myHomesound.play();
       firstTurn = false;
     }
     if(Greenfoot.mouseClicked(this))
     {
        if(myHomesound.isPlaying())
        {
            myHomesound.pause();
            setImage("mute.png");
        }else
        {
            myHomesound.play();
            setImage("sound_logo.png");
        }
     }
     if (Greenfoot.mouseClicked(Play.class))
     { 
        Greenfoot.delay(1);
        myHomesound.pause();
        Greenfoot.setWorld(new MyWorld());
        getWorld().removeObject(this); 
     }
    }
}
wiu0 wiu0

2024/5/4

#
Could you upload the game? Because there is nothing weird in your code :/
danpost danpost

2024/5/4

#
Newrestar wrote...
<< Code Omitted >>
A class is not an object that can be clicked on. Use a reference to the Play actor that is in your world.
You need to login to post a reply.