Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
add comment

2 Answers 2

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
spriteBatch.End();

spriteBatch.Begin();
// Draw score and other information
spriteBatch.End();
share|improve this answer
    
Aha! That simple! Great! Thanks! :) –  3D-kreativ Aug 5 '12 at 13:09
add comment

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
add comment

Your Answer

 
discard

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.