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

2015/12/8

I need help with a score counter here is my code:

coreypaul45 coreypaul45

2015/12/8

#
/** * Write a description of class Counter here. * * @author (your name) * @version (a version number or a date) */ public class Counter extends Actor { /** * 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() { // Add your action code here. setImage(new GreenfootImage("Score: " + score, 24, Color.GREEN, Color.Black)); } }
Super_Hippo Super_Hippo

2015/12/8

#
1. There is no 'score' variable. Add a line similar to this one outside methods:
private int score = 0;
2. Only change the image if the score actually changed, not every act cycle.
coreypaul45 coreypaul45

2015/12/9

#
Thanks all I need now is the color variable
Super_Hippo Super_Hippo

2015/12/9

#
You can start your code like this:
import greenfoot.*;
import java.awt.Color;
coreypaul45 coreypaul45

2015/12/11

#
Thanks
You need to login to post a reply.