This is a basic algorithm in Greenfoot regarding parallax scrolling.