Question

I'm trying to divide my program into model and view. At first I controlled a camera based on input and everything worked fine. Now I decided to create a CameraModel class and update the real camera based on properties of CameraModel. Problem occurs when I create a new Box2D Body - then screen flickers. Maybe it's not a camera issue, but it only happens when I'm using this code:

CameraModel model = level01.getCameraModel();
camera.up.set(model.getUp());
camera.position.set(model.getPosition());
camera.zoom = model.getZoom();

...instead of this:

Body playerModel = level01.getPlayer().getBody();
Vector2 Pos = playerModel.getPosition();
Vector3 wv = new Vector3(Pos.x,Pos.y,0.0f);
camera.up.x = (float) Math.cos(playerModel.getAngle());
camera.up.y = (float) Math.sin(playerModel.getAngle());
camera.position.x = wv.x + camera.up.x * 200f;
camera.position.y = wv.y + camera.up.y * 200f;

To be exact only when I'm using this line camera.position.set(model.getPosition());.Every other property is set without trouble. What could cause the flickering?

Was it helpful?

Solution

The problem was I had a messy code and was passing actual vectors, not copies... So view was jumping very very fast.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top