Just quickly (you've probably worked this out) but moving the call to updateImage() from the constructor to a method named public void addedToWorld(World w) should fix the problem.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | import greenfoot.*; import java.awt.Color; public class GameOver extends Actor { String msgTxt = "GAME OVER" ; public GameOver() { } public GameOver(String txt) { msgTxt = txt; } public void addedToWorld(World world) { GreenfootImage image = new GreenfootImage(world.getWidth(), world.getHeight()); image.setColor(Color.cyan); image.fill(); GreenfootImage txtImg = new GreenfootImage(msgTxt, 36 , Color.black, new Color( 0 , 0 , 0 , 0 )); image.drawImage(txtImg, (image.getWidth() - txtImg.getWidth()) / 2 , (image.getHeight() - txtImg.getHeight() / 2 )); setImage(image); } } |