strange camera issue - Libgdx scene2d

Hey,

so i made quite some progress with my game. But acidently i encountered a strange Problem.
I basicly set the position of the Camera to the player.
So if the player moves arount the camera follows him.
The player sets its position in the Act method to the position of the box 2d body.
The Player is basicly an extended actor, he has a sprite and some other features.
Now i made some background and a Menue Layer.
And if the player moves fast, the Menue moves for some pixels, depending on the speed, i guess 1-6 pixels in each direction, the background effects also.
What i mean is, if i create a solid, fixed wall left, and a test ball with some physics directly near the wall, basicly touching it, so that it cant move left, because theres the wall, and the player moves fast left, the sprite of the ball moves for a few pixels into the sprite of the Wall, but the physics body of the wall doesnt move.
And if the player moves fast, the other entities, same class as player, appear to move in front of the background even though they stay still.
The Same thing happens with the menues, they move for some pixels if the player moves.
I can fix this, if i call the Act of all actors (also the menues) like 2-3 times each render. but this cant be the solution right ?!
the Funny thing is after i stumpled upon this i checked my other libgdx projects and this “problem” is also in them, so it appears im doing something really really wrong in general.

this is my render method :

	
		@Override
		public void draw(){
		if (gameMap != null) gameMap.rendermap(this.getSpriteBatch());  // this renders the effects
		if (player != null){
		this.getCamera().viewportWidth = Gdx.graphics.getWidth();
		this.getCamera().viewportHeight = Gdx.graphics.getHeight();
		this.getCamera().position.set(player.sprite.getX(),player.sprite.getY(), 0);
		this.getSpriteBatch().setProjectionMatrix(this.getCamera().combined);}
		inpudhandling(); 
		updateUIPositions();
		super.draw();
		world.step(1/60f, 6, 2);
	}

if i try to render the effects (and the map) after setting the camera, there locations are wrong. (they get the ProjectionMatrix of this stages sprite batch)
Now i tryed to to let the camera be centered on the player with “look at”, but sadly i get a black screen if i do this.
If i cast the Stage Camera to a Orthogonal camera i also can use the update method on it, however it appears to make no difference.

now this gets called by the State Manager :

		GameStage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 60f));
		GameStage.draw();

if i switch the act and the draw in the Stage Manager makes no difference.
if i do a

super.act(Gdx.graphics.getDeltaTime());

after the

this.getSpriteBatch().setProjectionMatrix(this.getCamera().combined);}

in the draw metho, it appears to work, but then im basicly acting twice. if i only act there and im not letting the Stage Manager call the act the same problem happens.

act of the player :

//getting physics position
            Vector2 position = body.getPosition();
            // setting position of actor and sprite to physics location
            //actor
            this.setPosition(position.x-16,position.y-16);
            this.setRotation( MathUtils.radiansToDegrees*body.getAngle());
            // sprite
            actorPos = new Vector2(this.localToStageCoordinates(new Vector2(0,0)));
            sprite.setPosition(actorPos.x,actorPos.y);
            sprite.setRotation( MathUtils.radiansToDegrees*body.getAngle());

draw of the player :

public void draw(Batch batch,float dt) {
		if (this.sprite != null) sprite.draw(batch);
        }

menue background act :

        if (this.background != null) {background.setPosition(this.getX()+-getWidth()/2, this.getY()+-getHeight()/2);}

draw :

	public void draw(Batch batch,float dt) {

        super.draw(batch,dt);
	}

and its update method in the game :

    public void updateUIPositions(){
        actionMenue.setBounds(this.getCamera().position.x, this.getCamera().position.y, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    }

i now have the action menue as an “complete actor”, so i set the sprites position to the actor, but it really makes no difference, if i set it directly, or if i set it to the actor and also set the actor, ive tryed both.
Also as ive mentioned this problem also appears in a other “game” of me, but there i have not been working with Scene 2d, because of that i think im doing something wrong in the draw of the game.

i hope someone can help me.
thanks in advance

so ive tryed a lot today to get this working.
even if i failed, i found out something that maybe of use to solve this.
Ive added a fps label to the game. Its supposed to be at a static point at the top right.
first i tryed it with this :

Vector3 frameLabelPos = new Vector3(this.getCamera().unproject(new Vector3(x,y,0)));

however if i do it this way the same problems i have with the other stuff appears for this label.
but i found out that if i do it this way :

Vector3 frameLabelPos = new Vector3(player.getX()+Gdx.graphics.getWidth()/2-50,player.getY()+Gdx.graphics.getHeight()/2-10,0);

it works, and stays at the right place.
so it appears, if i let the camera unproject stuff for me, or get data from the camera, the camera returns me stuff that is “late”.
Or the Camera “moves” to its new position to slowly. This would absolutely explain all the trouble im having.
Its like if i set its position with

this.getCamera().position.set(player.sprite.getX(),player.sprite.getY(), 0);

it actually kind moves there, instead of “instantly beeing there”…

Why is this happening and how i can i fix this ?
(as ive mentioned, if i try to use “lookat” for the camera i always get a blank screen)

Seems like you are mixing update and drawing which will cause some things to be rendered for the previous frame and some for the current frame.

What you should probably be doing is:

Input Handle
Update everything
Update camera
Draw everything

Hey,
ive kinda hat it sorted, but then i acidently found this problem and startet to “move stuff” around and messed all order up.
But you were right, i cleared the render and update methods in the stagemanager and in the game and redone them according to your order. And now it works. :smiley:
so thanks for your help