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

Discussions

You need to login to take part
Rss

Current Discussions

dammnn

Scoreboard not working

By dammnn, with no replies.
I want to increase the Scoreboard if my Actor shoots an enemy. It doesn't work, here are my codes: First, the world: public class Level1 extends World { Scoreboard scoreboard = new Scoreboard(); public Level1() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(1000, 600, 1); populateWorld(); scoreboard = new Scoreboard(); } public void populateWorld() { addObject(new Mario(), 900, 100); for(int i = 0; i < 10; i++) { addObject(new Pilz(), Greenfoot.getRandomNumber(700), Greenfoot.getRandomNumber(600)); } for(int i = 0; i < 4; i++) { addObject(new Shyguy(), Greenfoot.getRandomNumber(500), Greenfoot.getRandomNumber(600)); } addObject(new Scoreboard(), 50, 20); } public Scoreboard getScoreboard() { return scoreboard; } } the Actor Scoreboard: public class Scoreboard extends Actor { private int score = 0; public void updateImage() { setImage(new GreenfootImage("Score: "+score, 25, Color.WHITE, new Color(0,0,0,0))); } public Scoreboard() { updateImage(); } public void addScore() { score++; updateImage(); } } and the Fireball Actor, which kills the enemy: public class Feuerball extends Actor { public int Scoreboard = 0; public void act() { move(12); if (isTouching(Shyguy.class) || isTouching(Shyguy2.class)) { ((Level1)getWorld()).getScoreboard().addScore(); removeTouching(Shyguy.class); removeTouching(Shyguy2.class); getWorld().removeObject(this); // Greenfoot.playSound(_soundFile_) } else if (isAtEdge()) getWorld().removeObject(this); } } can anybody find the prob?
1
2
3
4