I have tried implementing a basic 2D sidescroller camera in XNA, but I don't want it to be able to scroll past the edges of my tile map!
I tried to fix it, but when I get the left side working, the right stops working...
How do I do this right?
EDIT: After Anko
public Matrix transform;
Viewport view;
Vector2 center;
public void Update(GameTime gameTime, Player player) {
center = new Vector2(player.Position.X + (player.Bounds.Width / 2) - (960 / 2), 0);
float cameraX = center.X;
float cameraWidth = view.Width;
float worldWidth = 1760;
if (cameraX < 0)
cameraX = 0;
else if ( cameraX + cameraWidth > worldWidth)
cameraX = worldWidth - cameraWidth;
transform = Matrix.CreateTranslation(new Vector3(-cameraX, 0, 0));