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

2016/4/12

Stop backgroundmusic when game is over

Bassusour Bassusour

2016/4/12

#
Hi. So my problem is to stop the backgroundmusic from another class. The gameover method is located in another class, and the background music is located in the world class. So how do I stop it from another class? Here's what i've got. This is located in player 1
public boolean gameOver()
    {
        if ( fd_spist == 10)
        {
            FD_world world = (FD_world)getWorld().getObjects(FD_world.class).get(0);
            world.backgroundMusic.pause();
            return false;
        } 
        return true;
    }
danpost danpost

2016/4/12

#
How can you get a FD_world object from an FD_world object? Why would you want to when you already have it? Remove everything in line 5 from the first period on. except for the ending semi-colon.
Bassusour Bassusour

2016/4/12

#
But if I do that, i get the error "non-static variable backgroundMusic cannot be referenced from a static context" Here's the code
public boolean gameOver()
    {
        if ( fd_spist == 10)
        {
            FD_world.backgroundMusic.pause();
            return false;
        }  
        return true;
    }
danpost danpost

2016/4/12

#
Where did that line 5 come from? That is nothing like the way it started (up to where the first period was located).
You need to login to post a reply.