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

2014/8/29

How to make counter show score in GameOver world?

1
2
danpost danpost

2014/8/30

#
addObject(new Actor() { { setImage(new GreenfootImage("Final Score\n"+finalScore, 64, null, null)); } }, getWidth()/2, getHeight()/2);
This one line will create a new image with the final score, set it to the image of a new actor and place the actor in the center of your world.
JeppDev JeppDev

2014/8/30

#
Thank you very much :D I got it to work now your help is very much appreciated because i have been stuck and trying all sorts of stuff since yesterday
JeppDev JeppDev

2014/8/30

#
Is it possible if i have both score and time to make them both show in the GameOver world?
Super_Hippo Super_Hippo

2014/8/30

#
Sure. Just pass the time the same way as the score.
JeppDev JeppDev

2014/8/30

#
I can only pass one int to GameOver
Super_Hippo Super_Hippo

2014/8/30

#
You need to change (or add a new) constructor.
public GameOver(int finalScore, int time)
Then you can pass two ints.
JeppDev JeppDev

2014/8/30

#
Thanks
Baris Baris

2015/1/12

#
Can someone help me?, I cannt get my Counter to work.
I have added the code below in Counter (Actor)
    int score = 0;
    /**
     * Act - do whatever the Counter wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        setImage(new GreenfootImage("Score : " + score,20, Color.BLUE, Color.WHITE));
    }

    public void addScore()
    {
        score++;
    }
I have added the code below in Level1 (World)
    Counter counter = new Counter();
    /**
     * Constructor for objects of class Level1.
     * 
     */
    public Level1()
    {    
        super(600, 400, 1); 
        prepare(); //Names and Locations of all the Actors in Level1
    }

    public Counter getCounter()
    {
        return counter;
    }
danpost danpost

2015/1/12

#
To include the time also, the only thing in the code I provided above that you would need to change is the String within the GreenfootImage constructor call:
addObject(new Actor() { { setImage(new GreenfootImage("Final Score: "+finalScore\n\nTime: "+time, 64, null, null)); } }, getWidth()/2, getHeight()/2);
You need to login to post a reply.
1
2