Java 如何用不同的图像重复我的背景图像
我有一个背景图像,它会向左滚动并自动重复。但是,我希望它与我的可绘制文件夹中的另一个图像重复 我该怎么做Java 如何用不同的图像重复我的背景图像,java,android,android-studio,Java,Android,Android Studio,我有一个背景图像,它会向左滚动并自动重复。但是,我希望它与我的可绘制文件夹中的另一个图像重复 我该怎么做 import android.graphics.Bitmap; import android.graphics.Canvas; public class Background { private Bitmap image; private int x, y, dx; public Background(Bitmap res) { dx = G
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);
}
}
}
导入android.graphics.Bitmap;
导入android.graphics.Canvas;
公课背景{
私有位图图像;
私有整数x,y,dx;
公共背景(位图分辨率){
dx=GamePanel.MoveSpeed;
图像=分辨率;
}
公共无效更新(){
x+=dx;
如果(x<-游戏面板宽度){
x=0;
}
}
公共空白绘制(画布){
drawBitmap(图像,x,y,空);
if(x<0){
canvas.drawBitmap(图像,x+GamePanel.WIDTH,y,null);
}
}
}
如您所见,使用参数“res”调用此方法。
找到调用它的位置,并将参数更改为另一个图像
public Background(Bitmap res) {
dx = GamePanel.MoveSpeed;
image = res;
}