나는 Libgdx에서 게임을 만들고 있는데,이 게임에서 단어를 위로부터 아래로 공을 떨어 뜨리고 배경을 단어쪽으로 이동시키고 그에 따라 카메라를 업데이트하려고합니다. 내 코드 내 코드와libgdx에서 배경 화면을 이동하는 방법은 무엇입니까?
public WorldRenderer(SpriteBatch spriteBatch, World world){
this.world = world;
this.camera = new OrthographicCamera(FRUSTUM_WIDTH, FRUSTUM_HEIGHT);
this.camera.position.set(FRUSTUM_WIDTH/2, FRUSTUM_HEIGHT/2, 0);
this.spriteBatch = spriteBatch;
positionBGY1 = 0;
positionBGY2 = 0;
}
public void render(World world, float deltaTime){
if(world.ball.position.y > - camera.position.y){
camera.position.y = world.ball.position.y;
}
if(camera.position.y<0)
camera.position.y=world.ball.position.y;
camera.update();
spriteBatch.setProjectionMatrix(camera.combined);
renderBackground();
renderObjects(world, deltaTime);
}
private void calculateBGPosition(){
positionBGY2 = positionBGY1 + (int)FRUSTUM_HEIGHT;
if(camera.position.y >= positionBGY2){
positionBGY1 = positionBGY2;
}
}
private void renderBackground() {
spriteBatch.disableBlending();
spriteBatch.begin();
spriteBatch.draw(Assets.gamebackgroundRegion, camera.position.x - FRUSTUM_WIDTH/2, positionBGY1 - FRUSTUM_HEIGHT/2, FRUSTUM_WIDTH, 1.5f * FRUSTUM_HEIGHT);
spriteBatch.draw(Assets.gamebackgroundRegion2, camera.position.x - FRUSTUM_WIDTH/2, positionBGY2 - FRUSTUM_HEIGHT/2, FRUSTUM_WIDTH, 1.5f * FRUSTUM_HEIGHT);
calculateBGPosition();
spriteBatch.end();
}
문제는 배경 화면이 화면 밖으로 넘어 이동하지 않고 카메라가 공의 움직임과 공을 업데이트되지 않습니다는 ... 아래와 같습니다. 지금까지 카메라가 난 그냥 이런 짓을 했을까 공을 이동하는 것과 같은
float speed = 1;
positionBGY1+=deltaTime*speed;
positionBGY2+=deltaTime*speed;
:
안녕하세요, 감사에 대해 걱정할 필요 없다 있도록 ParrallaxLayer 및 ParrallaxBackground 클래스
을 사용하고 그것은 백그라운드 작업을 최적화. 나는 이미 내 문제를 알아 냈다. –