Example #1
0
        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            _bitmapFont = Content.Load<BitmapFont>("montserrat-32");

            var viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
            _camera = new Camera2D(viewportAdapter)
            {
                Zoom = 2.0f
            };
            _sceneGraph = new SceneGraph();

            var carHullTexture = Content.Load<Texture2D>("car-hull");
            var carHullSprite = new Sprite(carHullTexture);
            var carWheelTexture = Content.Load<Texture2D>("car-wheel");
            var carWheelSprite = new Sprite(carWheelTexture);

            _carNode = new SceneNode("car-hull", viewportAdapter.Center.ToVector2());
            _carNode.Entities.Add(carHullSprite);

            _leftWheelNode = new SceneNode("left-wheel", new Vector2(-29, 17));
            _leftWheelNode.Entities.Add(carWheelSprite);

            _rightWheelNode = new SceneNode("right-wheel", new Vector2(40, 17));
            _rightWheelNode.Entities.Add(carWheelSprite);

            _carNode.Children.Add(_rightWheelNode);
            _carNode.Children.Add(_leftWheelNode);
            _sceneGraph.RootNode.Children.Add(_carNode);
        }
        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;
        }
Example #3
0
        protected override void Initialize()
        {
            base.Initialize();

            var viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
            _camera = new Camera2D(viewportAdapter);
        }
Example #4
0
 protected override void Initialize()
 {
     var viewPortAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
     regularCoin.InitializeList(coins);
     camera = new Camera2D(viewPortAdapter);
     base.Initialize();
 }
        public void BoxingViewportAdapter_Pillarbox_Test()
        {
            var graphicsDevice = TestHelper.CreateGraphicsDevice();
            var viewportAdapter = new BoxingViewportAdapter(graphicsDevice, 800, 480);

            graphicsDevice.Viewport = new Viewport(0, 0, 900, 500);
            viewportAdapter.OnClientSizeChanged();

            Assert.AreEqual(833, graphicsDevice.Viewport.Width);
            Assert.AreEqual(500, graphicsDevice.Viewport.Height);
            Assert.AreEqual(BoxingMode.Pillarbox, viewportAdapter.BoxingMode);
        }
        public void BoxingViewportAdapter_Letterbox_Test()
        {
            var graphicsDevice = TestHelper.CreateGraphicsDevice();
            var viewportAdapter = new BoxingViewportAdapter(graphicsDevice, 800, 480);

            graphicsDevice.Viewport = new Viewport(0, 0, 1024, 768);
            viewportAdapter.OnClientSizeChanged();

            Assert.AreEqual(1024, graphicsDevice.Viewport.Width);
            Assert.AreEqual(614, graphicsDevice.Viewport.Height);
            Assert.AreEqual(BoxingMode.Letterbox, viewportAdapter.BoxingMode);
        }
Example #7
0
        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            var viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
            _camera = new Camera2D(viewportAdapter);

            var logoTexture = Content.Load<Texture2D>("logo-square-128");
            _sprite = new Sprite(logoTexture)
            {
                Position = viewportAdapter.Center.ToVector2()
            };

            var particleTexture = new Texture2D(GraphicsDevice, 1, 1);
            particleTexture.SetData(new[] { Color.White });

            ParticleInit(new TextureRegion2D(particleTexture));
        }
 /// <summary>
 /// Allows the game to perform any initialization it needs to before starting to run.
 /// This is where it can query for any required services and load any non-graphic
 /// related content.  Calling base.Initialize will enumerate through any components
 /// and initialize them as well.
 /// </summary>
 protected override void Initialize()
 {
     var virtualSize = SceneManager.Instance.VirtualSize;
     ViewportAdapter = new BoxingViewportAdapter(this.Window, GraphicsDevice, (int)virtualSize.X, (int)virtualSize.Y);
     base.Initialize();
 }
Example #9
0
        protected override void LoadContent()
        {
            var viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
            _camera = new Camera2D(viewportAdapter);
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            _backgroundTexture = Content.Load<Texture2D>("vignette");
            _bitmapFont = Content.Load<BitmapFont>("montserrat-32");
        }