Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无限背景动画_Android - Fatal编程技术网

Android 无限背景动画

Android 无限背景动画,android,Android,我为一款Android 2D游戏制作了一个无限的背景,但是背景只会滚动一次,不会循环。我怎样才能解决这个问题 另一个问题:我如何使相同的背景从上到下?玩游戏 这是我的班级(代码): 公共类GameView扩展视图实现可运行{ 专用静态最终整数间隔=10; 私有布尔运行=真; 私营企业; 私人油漆; 私有整数z=0; int-sx; 位图背景; 公共游戏视图(上下文){ 超级(上下文); 油漆=新油漆(); background=BitmapFactory.decodeResource(getR

我为一款Android 2D游戏制作了一个无限的背景,但是背景只会滚动一次,不会循环。我怎样才能解决这个问题

另一个问题:我如何使相同的背景从上到下?玩游戏

这是我的班级(代码):

公共类GameView扩展视图实现可运行{
专用静态最终整数间隔=10;
私有布尔运行=真;
私营企业;
私人油漆;
私有整数z=0;
int-sx;
位图背景;
公共游戏视图(上下文){
超级(上下文);
油漆=新油漆();
background=BitmapFactory.decodeResource(getResources(),R.drawable.back);
Thread myThread=新线程(此线程);
myThread.setPriority(Thread.MIN_PRIORITY);
myThread.start();
}
@凌驾
公开募捐{
(跑步时){
试一试{
睡眠(间隔);
}捕捉(中断异常e){
Log.e(“游戏”,“游戏循环完成!”);
}
更新();
}
}
私有void更新(){
如果(y
public class GameView extends View implements Runnable {
    private static final int INTERVAL = 10;
    private boolean running = true;
    private int y;
    private Paint paint;
    private int z = 0;
    int sx;
    Bitmap background;

    public GameView(Context context){
        super(context);
        paint = new Paint();
        background = BitmapFactory.decodeResource(getResources(), R.drawable.back);
        Thread myThread = new Thread(this);
        myThread.setPriority(Thread.MIN_PRIORITY);
        myThread.start();           
    }

    @Override
    public void run() {
        while (running) {
            try {
                Thread.sleep(INTERVAL);
            } catch (InterruptedException e) {
                Log.e("Game", "Gameloop finished!");
            }
            update();
        }
    }

    private void update() {
        if (y < getHeight()) {
            y += 5;
        } else {
            y = 0;
        }
        postInvalidate();
    }

    public void draw(Canvas canvas) {
        super.draw(canvas);
        z = z-10;
        if(z == -sx) {
            z = 0;
            canvas.drawBitmap(background, z, 0, null);
        } else {
            canvas.drawBitmap(background, z, 0, null);  
        }
    }

    public void release() {
        running = false;
    }
}