How can I track a falling ball with a camera?
- by Jason
I have been trying to get my camera to follow a falling ball but with no success.
here is the code
float cameraY = (FrustumHeight / 2)+((ball.getPosition().y) /2) - (FrustumHeight /2);
if (cameraY < FrustumHeight/2 )
cameraY = FrustumHeight/2;
camera.position.set(0f,cameraY, 0f);
Gdx.app.log("test",camera.position.toString());
camera.update();
camera.apply(Gdx.gl10);
batch.setProjectionMatrix(camera.combined);
batch.begin();
batch.draw(backgroundRegion, camera.position.x - FrustumWidth / 2,
-cameraY - (FrustumHeight/2) , 320, 480);
batch.draw(ballTexture, (camera.position.x - FrustumWidth / 2) + ball.getPosition().x,-cameraY + ball.getPosition().y - (FrustumHeight/2) ,
32, 32);
I'm sure I am doing this completely wrong - what is the correct way to do this?