0
\$\begingroup\$

On the internet, I saw videos and tutorials about screen scrolling. But those only show how to keep the player always in the center of the camera.

I want my camera to scroll over the level, following the character, only when the character is within the 20% border of the screen.

So, when the player is not close to the edge of the window then the camera stays in place and not follow the player and when the player crosses this "scrolling line" the camera should smoothly follow hit. Let's say that my game window is 1000px wide and 500px high, but the game map is 3000px wide and 3000px high.

\$\endgroup\$
  • \$\begingroup\$ @AlexandreVaillancourt, what is the difference between SpriteBatch.GraphicsDevice.Viewport.Width and GraphicsDeviceManager.PreferredBackBufferWidtht? \$\endgroup\$ – Karol Jun 10 at 15:17
  • \$\begingroup\$ I don't know what these functions do. I have never worked with XNA/MonoGame. \$\endgroup\$ – Vaillancourt Jun 10 at 16:14
  • \$\begingroup\$ You basically answered the question yourself. "when the player is not close to the edge of the window then the camera stays in place" Most mechanisms call an update-function to update the camera respective to the players position. Just add an If-clause to update the position only if the player is out of specified bounds. \$\endgroup\$ – Pavel Slesinger Jun 11 at 10:19

Your Answer

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

Browse other questions tagged or ask your own question.