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

2018/4/4

show score in my world

Miguel.Valdez Miguel.Valdez

2018/4/4

#
i made a class/actor that i want to show my score in the world.
1
2
3
4
5
6
7
public class ScoreCounter extends Actor
{
    public ScoreCounter()
    {
         setImage(new GreenfootImage("Score: ", 283, Color.WHITE, new Color(0,0,0,0)));
    }  
}
but how can i make this text show up in my world, as well to add "score" which represent when something is eaten(code i am posting, has an error for addObject)(this code is in my world)(the text commented out is what i had previously, but i can change color in that part)
1
2
3
4
5
6
7
8
9
/**
 * Show our current score on screen.
 */
private void showScore()
{
    //showText("Score: " + score, 600, 20);
    ScoreCounter scorecounter = new ScoreCounter();
    addObject(scorecounter, + score, 600, 20);
}
danpost danpost

2018/4/4

#
The addObject method requires exactly three arguments -- an Actor object followed by two int values. See my Value Display Tutorial scenario for information regarding this issue.
Miguel.Valdez Miguel.Valdez

2018/4/5

#
so now i have this in my world
1
2
private int score;
private Actor scoreDisplay;
1
2
3
4
5
6
private void showScore()
{
    String text = "Score: " +score;
    GreenfootImage image = new GreenfootImage(text, 283, Color.WHITE, new Color(0,0,0,0));
    scoreDisplay.setImage(image);
}
but how exactly can i make it display in a certatin area in my world?
danpost danpost

2018/4/5

#
Miguel.Valdez wrote...
so now i have this in my world << Code Omitted >> but how exactly can i make it display in a certatin area in my world?
Create an actor, assign it to scoreDisplay and add it into the world (all in your world constructor).
You need to login to post a reply.