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

2021/1/20

Using counter through different worlds

jenhasnofriends jenhasnofriends

2021/1/20

#
Hi! I'm creating a game and I need help making a current score and high score which I need to use in two different worlds.
public class Counter1 extends Actor
{
    /**
     * Act - do whatever the Counter wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    int score = 0;
    public Counter1()
    {
        setImage(new GreenfootImage("Score: " + score, 50, Color.WHITE, Color.BLACK));
    }
    public void act() 
    {
        setImage(new GreenfootImage("Score: " + score, 50, Color.WHITE, Color.BLACK));
    } 
    public void addScore(int scoreUp)
    {
        score =+ score + scoreUp;
    }
}
danpost danpost

2021/1/20

#
Show codes of worlds and class where world transition takes place (if not in one of the world classes.
You need to login to post a reply.