0
\$\begingroup\$

Alright so after some long hours and a lot of work I finally understand the basics of Monogame and am able to create a simple game with menu, sounds, the whole lot. But now I want to create a map game, like for example in stardew valley you're able to walk around and the camera will move with your character to a different location. Another example is terraria where you can keep going left for ages and the game will keep on going.

Currently for me I'm limited to the window box of my screen.

\$\endgroup\$
  • \$\begingroup\$ In 2d, Translate the world, not the camera. The player will always be locked at dead center. \$\endgroup\$ – Krythic Dec 4 '16 at 17:06
2
\$\begingroup\$

Use Matrix.CreateTranslation to create a matrix which moves the camera a certain offset, then pass it as the last parameter to SpriteBatch.Begin for 2D, or to your Effect for 3D. Draw objects at their world position as desired.

This is the standard way of doing camera movement which has the GPU do the heavy lifting on where object will end up, and will allow you to easily combo it with other matrix transformations (such as Matrix.CreateScale for zoom).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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