How do I get my 'space' background movine forward.?This will make my rocket look like it is moving forwards.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | //in your world class private int imageCount = 0 ; private GreenfootImage bgImage = new GreenfootImage( "imageName.png" ); public void act() { imageCount -= 5 ; //(or any other value; small -> slow moving, big -> fast movement) drawBackgroundImage(); } public void drawBackgroundImage() { if (imageCount > bgImage.getWidth()) { imageCount += bgImage.getWidth(); } int temp = imageCount; getBackground().drawImage(bgImage, temp, 0 ); getBackground().drawImage(bgImage, temp + bgImage.getWidth(), 0 ); } |
1 | if (imageCount < -bgImage.getWidth()) { |