Пример #1
0
        private void DrawParallax(ArenaLayer layer)
        {
            if (layer.ParallaxName != "")
            {
                var oldState = GraphicsDevice.BlendState;

                // Modify renderstate for parallax.
                GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
                GraphicsDevice.BlendState = BlendState.AlphaBlend;
                GraphicsDevice.DepthStencilState = DepthStencilState.None;

                // Render looping parallax as two huge triangles.
                _effect.Texture = AssaultWingCore.Instance.Content.Load<Texture2D>(layer.ParallaxName);
                var texCenter = GetScale(layer.Z) * CurrentLookAt / _effect.Texture.Dimensions();
                var texCornerOffset = new Vector2(
                    Viewport.Width / (2f * _effect.Texture.Width) / ZoomRatio,
                    Viewport.Height / (2f * _effect.Texture.Height) / ZoomRatio);
                _vertexData[0].TextureCoordinate = texCenter - texCornerOffset;
                _vertexData[1].TextureCoordinate = texCenter + texCornerOffset.MirrorX();
                _vertexData[2].TextureCoordinate = texCenter + texCornerOffset.MirrorY();
                _vertexData[3].TextureCoordinate = texCenter + texCornerOffset;
                _effect.CurrentTechnique.Passes[0].Apply();
                GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleStrip, _vertexData, 0, 2);
            }
            // Modify renderstate for 3D graphics.
            GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
            GraphicsDevice.DepthStencilState = DepthStencilState.Default;
            GraphicsDevice.BlendState = BlendState.Opaque;
        }