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

2018/1/18

Creating ScoreCounter

Fizzy Fizzy

2018/1/18

#
Hi, struggling to make a game which uses score counter and I've got a problem.
public class Score extends Actor
{
    private int score=0;
     
    public void Score()
    {
        setImage(new GreenfootImage(200, 30));
        update();
    }
 
    public void addScore()
    {
        score++;
        update();
    }
     
    public void update()
    {
        GreenfootImage img = getImage();
        img.clear();
        img.setColor(Color.WHITE);
        img.drawString("Score: " + score/10,5 ,9 ); 
    }    
}
using this in counter actor and
((Score)getWorld().getObjects(Score.class).get(0)).addScore();
in anoter actor and
public Score score = new Score();
addObject (score, 200, 30);
this in my world. The problem is the following when i use "run" i can only see a part of the word "Score". but if i stop it and Right click and void Score() it gets normal..... . I am confused.
CxVercility CxVercility

2018/1/18

#
Did you try increasing the images width? Or rather, what did you try?
Fizzy Fizzy

2018/1/19

#
I tried many things, but the problem was, I had no act() but Score() in code.
danpost danpost

2018/1/19

#
Fizzy wrote...
I tried many things, but the problem was, I had no act() but Score() in code.
The Score class does not require an act method. There is nothing it will do on its own -- only when the score is actually changing (which is completely taken care of in the 'addScore' method.
You need to login to post a reply.