.


import greenfoot.*; public class ScrollWorld extends World { int baseX = 0; // 'bgi' stands for BackGroundImage GreenfootImage bgi = new GreenfootImage("scrolling_background.png"); int bgiWidth = bgi.getWidth(); public ScrollWorld() { super(800, 400, 1); update(); } public void act() { baseX = (baseX + bgiWidth - 1) % bgiWidth; update(); } private void update() { if (baseX != 0) getBackground().drawImage(bgi, baseX - bgiWidth, 0); if (baseX < getWidth()) getBackground().drawImage(bgi, baseX, 0); } }