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

2012/12/9

play again button on scoreboard

davemib123 davemib123

2012/12/9

#
Hi, how would I go about adding a "play again" button on the scoreboard? The scoreboard is the imported classes from within greenfoot.
danpost danpost

2012/12/9

#
Create an actor class to display a button object and code it to accept and act on a mouse click. Then have the world add a new button object in the world at a location that will not interfere with the scoreboard information.
davemib123 davemib123

2012/12/9

#
ah rite, good thinking I'll give it a go. I've tried this:
    public void act() 
    {
        if (Greenfoot.mouseClicked(this) )  
        {  
            Greenfoot.setWorld(new City());
        } 
    } 
but it doesnt seem to reset the world.
davemib123 davemib123

2012/12/10

#
this is how it looks: http://www.greenfoot.org/scenarios/5799 the play button appears on the scoreboard but then I cant click on it.
vonmeth vonmeth

2012/12/10

#
There isn't much to go on to help you with. Could you post some more of your code, or make the scenario open source?
danpost danpost

2012/12/11

#
Pause the scenario on the scoreboard screen and see if you can drag-n-drop the 'play' button. If not, add a 'setPaintOrder' statement to display the button on top of the scoreboard.
davemib123 davemib123

2012/12/11

#
danpost wrote...
Pause the scenario on the scoreboard screen and see if you can drag-n-drop the 'play' button. If not, add a 'setPaintOrder' statement to display the button on top of the scoreboard.
When the scenario is paused on the scoreboard screen I am able to move the play button but still no luck with the reset.
danpost danpost

2012/12/11

#
You will have to re-upload your scenario; this time make sure the 'Publish source code' checkbox is checked (anytime you update your scenario and you want the source published, you need to re-check the box).
davemib123 davemib123

2012/12/11

#
must have forgot to press that button. try now.
vonmeth vonmeth

2012/12/11

#
The problem comes from your gameOver() method. It is removing everything (including the PlayAgain button, and Scoreboard) and then adding it. The act method is constantly calling this method once the game is over. As it is adding and then removing it constantly, it never gets time to receive a mouse click. A few changes so this only gets called once, and it will work fine.
davemib123 davemib123

2012/12/11

#
vonmeth wrote...
The problem comes from your gameOver() method. It is removing everything (including the PlayAgain button, and Scoreboard) and then adding it. The act method is constantly calling this method once the game is over. As it is adding and then removing it constantly, it never gets time to receive a mouse click. A few changes so this only gets called once, and it will work fine.
that suggestion is ace. but how do I remove multiple classes? I know how to remove one class:
removeObjects(getObjects(Mover.class)); 
now if I want remove Counter.class and Bar.class how to I do that within the same statement? or is it a matter of just making separate removes for each of the classes I want removing.
vonmeth vonmeth

2012/12/11

#
Separate removes for each class, as far as I know. But, really you can fix this problem like this:
private boolean over;
// then in act
    public void act()  
    {   
        if (bar.value == 0 && !over){
            gameOver();
        } else {
           // all the other act code
        }
    }
// then in gameOver
    public void gameOver()
    {

        bgSound.stop();
        scoreSound.playLoop();
        removeObjects(getObjects(null)); 
        Saver saver = new Saver();
        saver.saveHighscore(theCounter.getValue());

        ScoreBoard board = new ScoreBoard(getWidth(), getHeight());
        addObject(board, getWidth() /2, getHeight() /2);
        addObject(new PlayAgain(), 393, 26);

        over = true; // so we don't run this again
    }
Even if you didn't remove the PlayAgain and ScoreBoard over and over, you still would be adding it over and over.
danpost danpost

2012/12/11

#
If you remove everything before adding the scoreboard and button, it would work just as well.
davemib123 davemib123

2012/12/11

#
good suggestions :) i'll have to test them when I get a chance.
You need to login to post a reply.