コード例 #1
0
        public void Draw(Camera2D camera, bool useMapBackgroundColor = false)
        {
            if(useMapBackgroundColor && BackgroundColor.HasValue)
                _graphicsDevice.Clear(BackgroundColor.Value);

            foreach (var layer in _layers)
                layer.Draw(camera);
        }
コード例 #2
0
        public void Camera2D_ContainsRectangle_Test()
        {
            var graphicsDevice = TestHelper.CreateGraphicsDevice();
            var camera = new Camera2D(graphicsDevice);

            Assert.AreEqual(ContainmentType.Intersects, camera.Contains(new Rectangle(-50, -50, 100, 100)));
            Assert.AreEqual(ContainmentType.Contains, camera.Contains(new Rectangle(50, 50, 100, 100)));
            Assert.AreEqual(ContainmentType.Disjoint, camera.Contains(new Rectangle(850, 500, 100, 100)));
        }
コード例 #3
0
        protected override void Initialize()
        {
            base.Initialize();

            _camera = new Camera2D(GraphicsDevice)
            {
                Zoom = 0.5f,
                Position = new Vector2(400, 440)
            };
        }
コード例 #4
0
        public void Camera2D_ContainsPoint_Test()
        {
            var graphicsDevice = TestHelper.CreateGraphicsDevice();
            var camera = new Camera2D(graphicsDevice);

            Assert.AreEqual(ContainmentType.Contains, camera.Contains(new Point(1, 1)));
            Assert.AreEqual(ContainmentType.Contains, camera.Contains(new Point(800, 480)));
            Assert.AreEqual(ContainmentType.Disjoint, camera.Contains(new Point(0, 0)));
            Assert.AreEqual(ContainmentType.Disjoint, camera.Contains(new Point(801, 481)));
        }
コード例 #5
0
 public void Camera2D_ContainsVector2_Test()
 {
     var graphicsDevice = TestHelper.CreateGraphicsDevice();
     var camera = new Camera2D(graphicsDevice);
     
     // the edge cases fall on the half pixel boundary
     Assert.AreEqual(ContainmentType.Disjoint, camera.Contains(new Vector2(0.45f, 0.45f)));
     Assert.AreEqual(ContainmentType.Contains, camera.Contains(new Vector2(800.45f, 480.45f)));
     Assert.AreEqual(ContainmentType.Contains, camera.Contains(new Vector2(0.55f, 0.55f)));
     Assert.AreEqual(ContainmentType.Disjoint, camera.Contains(new Vector2(800.55f, 480.55f)));
 }
コード例 #6
0
        public void Camera2D_LookAt_Test()
        {
            var viewportAdapter = Substitute.For<ViewportAdapter>();
            viewportAdapter.VirtualWidth.Returns(800);
            viewportAdapter.VirtualHeight.Returns(480);
            var camera = new Camera2D(viewportAdapter);
            
            camera.LookAt(new Vector2(100, 200));

            Assert.AreEqual(new Vector2(-300, -40), camera.Position);
        }
コード例 #7
0
        protected override void Initialize()
        {
            _viewportAdapter = new BoxingViewportAdapter(GraphicsDevice, 800, 480);
            _camera = new Camera2D(_viewportAdapter)
            {
                Zoom = 0.5f,
                Position = new Vector2(408, 270)
            };

            Window.AllowUserResizing = true;
            Window.ClientSizeChanged += (s, e) => _viewportAdapter.OnClientSizeChanged();

            base.Initialize();
        }
コード例 #8
0
        public void Camera2D_GetBoundingFrustum_Test()
        {
            var graphicsDevice = TestHelper.CreateGraphicsDevice();
            var camera = new Camera2D(graphicsDevice);
            var boundingFrustum = camera.GetBoundingFrustum();
            var corners = boundingFrustum.GetCorners();

            const float delta = 0.01f;
            TestHelper.AreEqual(new Vector3(0.5f, 0.5f, 1), corners[0], delta);
            TestHelper.AreEqual(new Vector3(800.5f, 0.5f, 1), corners[1], delta);
            TestHelper.AreEqual(new Vector3(800.5f, 480.5f, 1), corners[2], delta);
            TestHelper.AreEqual(new Vector3(0.5f, 480.5f, 1), corners[3], delta);
            TestHelper.AreEqual(new Vector3(0.5f, 0.5f, 0), corners[4], delta);
            TestHelper.AreEqual(new Vector3(800.5f, 0.5f, 0), corners[5], delta);
            TestHelper.AreEqual(new Vector3(800.5f, 480.5f, 0), corners[6], delta);
            TestHelper.AreEqual(new Vector3(0.5f, 480.5f, 0), corners[7], delta);
        }
コード例 #9
0
        public void Draw(Camera2D camera)
        {
            var renderOrderFunction = GetRenderOrderFunction();

            _spriteBatch.Begin(sortMode: SpriteSortMode.Immediate, blendState: BlendState.AlphaBlend,
                samplerState: SamplerState.PointClamp, transformMatrix: camera.GetViewMatrix());

            foreach (var tile in renderOrderFunction())
            {
                var region = _tiledMap.GetTileRegion(tile.Id);

                if (region != null)
                {
                    // not exactly sure why we need to compensate 1 pixel here. Could be a bug in MonoGame?
                    var tx = tile.X * (_tiledMap.TileWidth - 1);
                    var ty = tile.Y * (_tiledMap.TileHeight - 1);
                        
                    _spriteBatch.Draw(region, new Rectangle(tx, ty, region.Width, region.Height), Color.White);
                }
            }

            _spriteBatch.End();
        }