我正在开发一个使用libgdx for Android的简单游戏,我想移动背景场景,如果Bird正在前进。我试过互联网上的各种示例和代码来移动或翻译相机,但无济于事。请帮助我并提出一些代码来实现这一目标。
以下是我的代码片段:
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来移动相机。
感谢名单!
答案 0 :(得分:0)
您可以使用演员和动作
使用多个地面演员填充屏幕宽度。
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;
}
};