Saturday, April 20, 2019

xna - 2d camera shaking back and forth


I'm trying to create a smooth moving 2d camera but the camera is shaking back and forth 1 pixel.



Player camera rectangle:


public Rectangle recCamPosition(Global global)
{
return new Rectangle((int)Position.X, (int)Position.Y , 320, 240);
}

Camera rectangle:


public Rectangle recCamera(Global global)
{
return new Rectangle((int)_pos.X / global.zoom, (int)_pos.Y / global.zoom, 320, 240);

}

The move method:


public void physic(Vector2 position, Player player, GameTime time, Global global)
{
if(player.recCamPosition(global).X!=recCamera(global).X)
{
_pos.X+=(player.Position.X-160-recCamera(global).X)/16;
}
}



No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...