Search code examples
c#graphicsxnamonogame

XNA/MonoGame Viewport how to use it


Well I've read different articles and questions on stackoverflow. But everyone suggests to use camera with viewport. Why just don't move viewport itself? AFAIK from SFML example things outside viewport won't be drawed. But with your implemented camera you have to control which things should be drawn. Isn't it better just to control viewport instead of camera?


Solution

  • Correct, Viewport methods are limited to what the viewing perspective of the user is. If you refer to "Viewport" you can ensure that the boundary will be directly within that range.

    If you have an image that you are rendering to the screen, calling

    Viewport.Width
    

    will put your image directly outside of the viewing perspective.

    You have to then do

    Viewport.Width - myPicture.Width
    

    for it to be viewable within the set boundaries.