Reputation: 51
I have a background image that scrolls to the left and repeats itself. However, I want it to repeat with another image that is in my drawable folder.
How can I do this?
import android.graphics.Bitmap;
import android.graphics.Canvas;
public class Background {
private Bitmap image;
private int x, y, dx;
public Background(Bitmap res) {
dx = GamePanel.MoveSpeed;
image = res;
}
public void update() {
x += dx;
if (x < -GamePanel.WIDTH) {
x = 0;
}
}
public void draw(Canvas canvas) {
canvas.drawBitmap(image, x, y, null);
if (x < 0) {
canvas.drawBitmap( image, x + GamePanel.WIDTH, y, null);
}
}
}
Upvotes: 3
Views: 183
Reputation: 392
public Background(Bitmap res) {
dx = GamePanel.MoveSpeed;
image = res;
}
As you can see, you call this method with the parameter "res". Find where you call it and change the argument to the other image.
Upvotes: 1