Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to use the 2D camera, but just for a part of the screen? Perhaps I want some info on the screen about score and other things, but I want that at a fixed place, just like when not using a 2D camera?

share|improve this question
up vote 1 down vote accepted

Sure! Since there's no concept of 2D camera built into XNA, I am guessing that you are using some class to generate a ViewMatrix and passing that matrix as a parameter to SpriteBatch.Begin().

If that's the case, the solution is simple... All you have to do is draw your score and anything that you don't want to be affected by the camera in a separate SpriteBatch.Begin() / SpriteBatch.End() block, but without passing it the ViewMatrix. Example:

spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, camera.ViewMatrix);
// Draw game world

// Draw score and other information
share|improve this answer
Aha! That simple! Great! Thanks! :) – 3D-kreativ Aug 5 '12 at 13:09

Create a Vector2 called Camera. Say you want to show an object with respect to the camera, i.e. a non-HUD object, draw it at a position given by:

DrawPosition = ObjectPosition - CameraPosition;

For the score and other HUD stuff, don't consider the camera vector.

DrawPosition = ObjectPosition;

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.