protected override void Initialize() { base.Initialize(); // the default viewport adapater is the simplest, it doesn't do any scaling at all // but is used by a Camera2D if no other adapter is specified. // this is often useful if you have a game with a large map and you want the player to see // more of the map on a bigger screen. _defaultViewportAdapter = new DefaultViewportAdapter(GraphicsDevice); // the scaling viewport adapter stretches the output to fit in the viewport, ignoring the aspect ratio // this works well if the aspect ratio doesn't change a lot between devices // or you don't like the black bars of the boxing adapter _scalingViewportAdapter = new ScalingViewportAdapter(GraphicsDevice, 800, 480); // the boxing viewport adapter uses letterboxing or pillarboxing to maintain aspect ratio // it's a little more complicated and needs to listen to the window client size changing event _boxingViewportAdapter = new BoxingViewportAdapter(GraphicsDevice, 800, 480); Window.ClientSizeChanged += (s, e) => _currentViewportAdapter.OnClientSizeChanged(); // typically you'll only ever want to use one viewport adapter for a game, but in this sample we'll be // switching between them. _currentViewportAdapter = _boxingViewportAdapter; }
protected override void LoadContent() { _spriteBatch = new SpriteBatch(GraphicsDevice); _bitmapFont = Content.Load<BitmapFont>("montserrat-32"); _tiledMap = Content.Load<TiledMap>("level01"); var viewportAdapter = new ScalingViewportAdapter(GraphicsDevice, 800, 480); _camera = new Camera2D(viewportAdapter) { Zoom = 0.5f, Position = new Vector2(_tiledMap.WidthInPixels / 4f, _tiledMap.HeightInPixels / 4f) }; }