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

2015/10/15

World music recover paragraph Place the actor

brunocampos brunocampos

2015/10/15

#
example I put a song on a menu but when I play the game to start the music continues I'm an actor named " Start" , oh when I click it on the menu the menu music has to stop , as I do this ?
World
  subclass(Words) 
         subclass(Word1)


public class Main extends Words
{
    GreenfootSound myMusic = new GreenfootSound("Main Soundtrack.mp3");
     public void act(){
     myMusic.playLoop();
    }
}

Actor
    subclass(Buttons)
         subclass(Start)

public class Start extends Buttons
{
    public void act() 
    {   
    }
       
    public void startLevel(){ 
        if( Greenfoot.mouseClicked(this)){
            getWorld().GreenfootSound(myMusic.stop());
            
        }   
    }

}
danpost danpost

2015/10/15

#
Change line 26 to:
((Main)getWorld()).myMusic.stop();
The 'myMusic' field is in the Main class, so the compiler needs to be aware that the world returned by 'getWorld' is indeed a Main world.
You need to login to post a reply.