开发者

XNA: What is Viewport?

开发者 https://www.devze.com 2023-03-29 14:37 出处:网络
开发者_开发知识库In terms of 2D I don\'t understand what a viewport is and what it is used for.

开发者_开发知识库In terms of 2D I don't understand what a viewport is and what it is used for. I am trying to build a side-scroller and believe I need the viewport for the map scrolling part.


Consider a Tv displaying a scene, the viewport is simply the area of the scene that is captured by the camera.

Another way of thinking about it is the way some cameraman hold up their thumbs and index fingers to 'frame' a scene, or hold up a hollow picture frame, the light that passes through that frame is the viewport.

For a visual example, consider this gif, the green rectangle is the viewport:

XNA: What is Viewport?


The Viewport contains information about the actual current window displaying the game. If you are working in 2D, the main ones you'll be dealing with will be the Width, Height, AspectRatio (saves calculating it yourself), and if you're planning to deploy to 360, the TitleSafeArea (The rectangle safe to draw to on all TV's, older TV's will clip 5-10% of some of the edges)

You probably won't be changing the Width and Height of your window in runtime so if you store an X and a Y for the camera position, you can store the Width and Height of the screen and never have to look at the Viewport again except maybe to place HUD elements within the TitleSafeArea.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号