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

2013/7/1

Wombats - Add a counter to display how many leaves the wombat has eaten

mccarthym mccarthym

2013/7/1

#
Hi guys. I want to display the number of leaves eaten on the screen in Greenfoot in the most simplest way possible. How can I do this?
joeschmoe joeschmoe

2013/7/1

#
http://www.youtube.com/watch?v=WIifij-961o
JetLennit JetLennit

2013/7/1

#
Re posting of what he said but easier to view
mccarthym mccarthym

2013/7/2

#
Thank you so much. Will give this a go today.
mccarthym mccarthym

2013/7/2

#
Thanks guys. I've followed the tutorial and got the counter working. I've got in the Wombats code: - public int getLeavesEaten() { return leavesEaten; } Cant I somehow just display the variable leavesEaten on the world? I don't need anything fancy.
danpost danpost

2013/7/2

#
In the Wombat code, where you have 'eat(Leaf.class);', add with it 'updateCount(); and add the following method to the class:
private void updateCount()
{
    // create a replacement cell image for the background
    GreenfootImage image = new GreenfootImage("cell.jpg");
    // draw the score on the cell image
    image.drawString(""+leavesEaten, 8, 24);
    // draw the cell image onto the background
    getWorld().getBackground().drawImage(image, 0, 0);
}
mccarthym mccarthym

2013/7/2

#
Wow thanks danpost - that is perfect.
mccarthym mccarthym

2013/7/2

#
Thanks all for the help I really appreciate it.
You need to login to post a reply.