private static final String bgImageName = "watergoed.jpg"; private static final double scrollSpeed = 2.5; private static final int picHeight = (new GreenfootImage(bgImageName)).getHeight(); private GreenfootImage bgImage, bgBase; private int scrollPosition = 0; public game3() { super(900, 900, 1); setBackground(bgImageName); bgImage = new GreenfootImage(getBackground()); bgBase = new GreenfootImage(getWidth(), picHeight); bgBase.drawImage(bgImage, 0, 0); prepare(); } public void act() { scrollPosition += scrollSpeed; while(scrollSpeed > 0 && scrollPosition > -picHeight) scrollPosition -= picHeight; while(scrollSpeed < 0 && scrollPosition < 0) scrollPosition += picHeight; paint(scrollPosition); } private void paint(int position) { GreenfootImage bg = getBackground(); bg.drawImage(bgBase,0,position); bg.drawImage(bgImage,0 , position + picHeight); }

