/* (c) 2015 Thomas Smits */
package de.smits_net.games.framework.images;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;

/**
 * Auto scrolling background image for a game. The image
 *
 * @author Thomas Smits
 */
public class Background {

    /** Current scroll position */
    private double scroll;

    /** Scroll speed */
    private double speed;

    /** The image */
    protected BufferedImage background;

    /**
     * Creates a new background image.
     *
     * @param speed speed of the scroll operation
     * @param width width of the image
     * @param height height of the image
     */
    public Background(double speed, int width, int height) {
        background = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        this.speed = speed;
    }

    /**
     * Move the image with the given speed.
     */
    public void move() {
        scroll += speed;

        if (-scroll > getWidth()) {
            scroll = 0;
        }
    }

    /**
     * Get the width of the image.
     *
     * @return the width in pixel.
     */
    public int getWidth() {
        return background.getWidth();
    }

    /**
     * Get the height of the image.
     *
     * @return the height in pixel.
     */
    public int getHeight() {
        return background.getHeight();
    }

    /**
     * Draw the background picture.
     *
     * @param g the graphics context to draw into
     * @param observer the image observer
     */
    public void draw(Graphics g, ImageObserver observer) {
        g.drawImage(background, (int)scroll, 0, observer);
        g.drawImage(background, background.getWidth() + (int)scroll, 0, observer);
    }
}

@@ -827,32 +827,266 @@
 = speed;%0A    %7D%0A%0A
+    /**%0A     * Creates a new background image.%0A     *%0A     * @param speed speed of the scroll operation%0A     */%0A    public Background(double speed, BufferedImage image) %7B%0A        background = image;%0A        this.speed = speed;%0A    %7D%0A%0A
     /**%0A     * M

Create background from image directly.