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

2017/4/28

Code to make a number gradually grow

RustuMan RustuMan

2017/4/28

#
I made a score. My code is below. However I want the score to increase as the game continues. Right now its just static.
public class counter extends Actor
{
    int score = 0 ;
   
    public void act() 
    {
        setImage(new GreenfootImage("Score : " + score, 30, Color.BLACK, Color.WHITE));
    }
    public void addScore()
    {
        score++;
    }
}
Yehuda Yehuda

2017/4/28

#
Your addScore method increases the score. Whenever you want to increase the score call that method. If the way you want the counter to work is that the whole game it just continually increases as opposed to every time something happens, then just put 'score++' in the act and delete the addScore method since you're anyway constantly increasing it.
RustuMan RustuMan

2017/4/28

#
So how would that look. Its not really working for me.
danpost danpost

2017/4/29

#
RustuMan wrote...
So how would that look. Its not really working for me.
Insert the following line in the act method:
addScore();
You need to login to post a reply.