Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.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
在libgdx游戏(android)中移动背景屏幕_Android_Camera_Screen_Libgdx - Fatal编程技术网

在libgdx游戏(android)中移动背景屏幕

在libgdx游戏(android)中移动背景屏幕,android,camera,screen,libgdx,Android,Camera,Screen,Libgdx,我正在用libgdx为Android开发一个简单的游戏,我想移动背景场景,就像小鸟在向前移动一样。我尝试了互联网上的各种例子和代码来移动或翻译相机,但都没有用。请帮助我,并建议一些代码来完成这一点 以下是我的代码片段: x+=0.1; trunk_rec.x-=10; trunk1_rec.x-=10; bird_rec.y-=5; if(trunk_rec.x<0) {

我正在用libgdx为Android开发一个简单的游戏,我想移动背景场景,就像小鸟在向前移动一样。我尝试了互联网上的各种例子和代码来移动或翻译相机,但都没有用。请帮助我,并建议一些代码来完成这一点

以下是我的代码片段:

x+=0.1;
            trunk_rec.x-=10;
            trunk1_rec.x-=10;
            bird_rec.y-=5;
            if(trunk_rec.x<0)
            {
                trunk_rec.x=trunk1_rec.x=900;
            }

            camera.translate(1,0);
            camera.update();
            game.batch.setProjectionMatrix(camera.combined);

            game.batch.begin();
            game.batch.draw(bg,0, 0,800,500);

            game.batch.draw(trunk,trunk_rec.x,trunk_rec.y);
            game.batch.draw(trunk,trunk1_rec.x,trunk1_rec.y);
            game.batch.draw(bird,bird_rec.x,bird_rec.y);

            game.batch.end();

            if(trunk_rec.x==bird_rec.x)
            {
                score++;
            }

            if(Gdx.input.isTouched())
            {
                bird_rec.y+=30;
            }

            if((trunk_rec.overlaps(bird_rec))|| trunk1_rec.overlaps(bird_rec) || bird_rec.y<10)
            {
                Gdx.app.exit();
                System.out.println("Score is "+score);
            }
我也尝试使用camera.position移动相机


塔克斯

你可以使用演员和动作

使用多个地面演员填充屏幕宽度

 if(isout){
 isout=false;
 ground1.addAction(Actions.sequence(Actions.moveTo(-ground.getWidth(),ground.getY(),duration),isDone));
 }
 Action isDone = new Action() {

    @Override
    public boolean act(float delta) {
                             isout=true;
                             ground1.setPosition(screenWidth,ground.getY());
        return true;
    }
};

更好的方法是移动鸟而不是背景。向我们展示背景/鸟类渲染的代码。@noone:但这是必需的!!