My project works in the Greenfoot editor, but when I export it to a .jar file, the Greenfoot does not repaint the screen, it just paints over the last frame. Any ideas?


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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.*; import java.util.*; public class SJHS extends World { public int score, level; int playing; GreenfootSound backgroundMusic[] = { new GreenfootSound( "yaketysax.mp3" ), new GreenfootSound( "yaketysax.mp3" ), new GreenfootSound( "yaketysax.mp3" ), new GreenfootSound( "yaketysax.mp3" ), new GreenfootSound( "yaketysax.mp3" ), new GreenfootSound( "yaketysax.mp3" ), new GreenfootSound( "yaketysax.mp3" ), new GreenfootSound( "yaketysax.mp3" ), new GreenfootSound( "yaketysax.mp3" ), new GreenfootSound( "yaketysax.mp3" ), new GreenfootSound( "yaketysax.mp3" ), new GreenfootSound( "yaketysax.mp3" ), new GreenfootSound( "centipede.mp3" )}; /** * Constructor for objects of class SJHS. * */ public SJHS() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super ( 1100 , 600 , 1 ); addObject( new Moloney(), 300 , 200 ); Generator.generateWorld( this , new ArrayList<Room>()); playing = Greenfoot.getRandomNumber(backgroundMusic.length); for ( int i = 0 ; i < backgroundMusic.length - 1 ; i++) { backgroundMusic[i].setVolume( 45 ); } for ( int i = backgroundMusic.length - 1 ; i < backgroundMusic.length; i++) { backgroundMusic[i].setVolume( 100 ); } backgroundMusic[playing].play(); updateScore(); } public void act() { handleMusic(); if (getObjects(Moloney. class ).size() == 0 ) { getBackground().drawString( "You lose!" , getWidth() / 2 , getHeight() / 2 ); } else if (getObjects(Student. class ).size() == 0 ) { level++; Moloney moloney = (Moloney)getObjects(Moloney. class ).get( 0 ); for ( int i = 0 ; i < Math.log(level * 12 ) / Math.log( 1.2 ); i++) { Student placed = new Student(); addObject(placed, Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(getHeight())); while (moloney.intersectingStudent()) placed.setLocation(Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(getHeight())); } } } public void handleMusic() { if (!backgroundMusic[playing].isPlaying()) { playing = Greenfoot.getRandomNumber(backgroundMusic.length); backgroundMusic[playing].setVolume( 45 ); backgroundMusic[playing].play(); } } public void updateScore() { GreenfootImage background = new GreenfootImage(getWidth(), getHeight()); Font larger = background.getFont().deriveFont( 28 .0f); background.setFont(larger); background.setColor(Color.black); background.drawString( "Click to shoot Dress Codes at people. Don't let the students run into you!" , 45 , 50 ); background.drawString( "Score: " + score, 45 , 100 ); background.drawString( "Level: " + level, 45 , 150 ); setBackground(background); } } |
1 | GreenfootImage background = getBackground(); |