1
\$\begingroup\$

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?

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

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();
\$\endgroup\$
0
0
\$\begingroup\$

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;

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .