Beispiel #1
0
        public override void Draw(GameTime gameTime)
        {
            if (!Visible || !Enabled || SpriteBatch == null)
            {
                return;
            }

            if (Texture != null && !Texture.IsDisposed)
            {
                // Create our Translation Based on our Camera's Offset factoring a speed value
                float x = (CameraOffsetX + (CameraOffsetX * ScrollSpeed));

                // Create our Translation Matrix Based off the camera's X offset
                Matrix translation = Matrix.CreateTranslation(new Vector3(x, CameraOffsetY, 0));

                if (SetShaderParameters != null)
                {
                    SetShaderParameters.Invoke(gameTime);
                }

                // Render with a custom effect
                if (CustomEffect != null)
                {
                    // Begin our Sprite Batch
                    SpriteBatch.Begin(SpriteSortMode, BlendMode, null, null, null, CustomEffect, translation);

                    // Loop thru Each Pass in our Shader
                    foreach (EffectPass pass in CustomEffect.CurrentTechnique.Passes)
                    {
                        pass.Apply();

                        // Begin rendering with this sprite mode
                        SpriteBatch.Draw(Texture, Position, new Rectangle(0, 0, Texture.Width, Texture.Height),
                                         Color, Rotation % Circle, Origin, Scale, _SpriteEffect, _Depth);
                    }

                    // End the sprite batch
                    SpriteBatch.End();
                }
                else
                {
                    // Begin our Sprite Batch | WHY IS SAMPLER STATE, DEPTH AND RASTER STATE PROPERTYS?
                    SpriteBatch.Begin(SpriteSortMode, BlendMode, null, null, null, null, translation);

                    SpriteBatch.Draw(Texture, Position, new Rectangle(0, 0, Texture.Width, Texture.Height), Color,
                                     Rotation % Circle, Origin, Scale, _SpriteEffect, _Depth);

                    SpriteBatch.End();
                }
            }

            if (ShowBoundingBox)
            {
                BoundingBoxRenderer.Draw(gameTime);
            }

            base.Draw(gameTime);
        }
Beispiel #2
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            // Set our Custom Effect Parameters
            if (SetShaderParameters != null)
            {
                SetShaderParameters.Invoke(gameTime);
            }
        }
        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);

            if (Texture != null && GameScreen != null && GameScreen.SpriteBatch != null && CurrentSequence != null && CurrentSequence.Frames.Count > 0 && CurrentFrameIndex < CurrentSequence.Frames.Count)
            {
                if (Texture.IsDisposed)
                {
                    return;
                }

                Vector3 pos = Vector3.Add(new Vector3(Position.X, Position.Y, 0),
                                          new Vector3(CameraOffsetX, CameraOffsetY, 0));

                // Create our Translation Based on our Camera's Offset
                Matrix translation = Matrix.CreateTranslation(pos);

                if (SetShaderParameters != null)
                {
                    SetShaderParameters.Invoke(gameTime);
                }

                if (CustomEffect != null)
                {
                    // Begin our Sprite Batch
                    GameScreen.SpriteBatch.Begin(SpriteSortMode, BlendState.AlphaBlend, null, null, null, CustomEffect, translation);

                    // Loop thru Each Pass in our Shader
                    foreach (EffectPass pass in CustomEffect.CurrentTechnique.Passes)
                    {
                        // Begin the pass
                        pass.Apply();

                        GameScreen.SpriteBatch.Draw(Texture, Vector2.Zero, CurrentSequence.Frames[CurrentFrameIndex].SourceRectangle,
                                                    Color.White, Rotation % Circle, Origin, Scale, SpriteEffects, 0f);
                    }

                    // End the sprite batch
                    GameScreen.SpriteBatch.End();
                }
                else
                {
                    // Begin our Sprite Batch
                    GameScreen.SpriteBatch.Begin(SpriteSortMode, BlendState.AlphaBlend, null, null, null, null, translation);

                    GameScreen.SpriteBatch.Draw(Texture, Vector2.Zero,
                                                CurrentSequence.Frames[CurrentFrameIndex].SourceRectangle, Color,
                                                Rotation % Circle, Origin, Scale, SpriteEffects, 0f);

                    GameScreen.SpriteBatch.End();
                }
            }
        }
        public override void Update(GameTime gameTime)
        {
            World = Matrix.CreateTranslation(Position);

            if (Trunk != null)
            {
                UpdateTreeNode(Camera.BoundingFrustum, Trunk, false, gameTime);
            }

            // Setup our Shader
            if (SetShaderParameters != null)
            {
                SetShaderParameters.Invoke(gameTime);
            }

            base.Update(gameTime);
        }
Beispiel #5
0
        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);

            if (!Visible)
            {
                return;
            }

            // Set our Custom Effect Parameters
            if (SetShaderParameters != null)
            {
                SetShaderParameters.Invoke(gameTime);
            }

            if (CustomEffect != null)
            {
                foreach (EffectPass pass in CustomEffect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, _verts, 0, 2);
                }
            }
        }
Beispiel #6
0
        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);

            World = Matrix.CreateScale(Scale) *
                    Matrix.CreateRotationY(Rotation.Y) *
                    Matrix.CreateRotationX(Rotation.X) *
                    Matrix.CreateRotationX(Rotation.Z) *
                    Matrix.CreateTranslation(Position);

            if (VertexBuffer != null && IndexBuffer != null)
            {
                // Pass our Index Buffer and our Vertex Buffer to the Graphics Device
                GraphicsDevice.Indices = IndexBuffer;
                GraphicsDevice.SetVertexBuffer(VertexBuffer);

                if (CustomEffect != null)
                {
                    // Setup our Shader
                    if (SetShaderParameters != null)
                    {
                        SetShaderParameters.Invoke(gameTime);
                    }

                    foreach (EffectPass p in CustomEffect.CurrentTechnique.Passes)
                    {
                        p.Apply();
                        GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, _width * _height, 0, TriangleCount);
                    }
                }
                else
                {
                    RasterizerState state = new RasterizerState();

                    state.FillMode = FillMode;
                    state.CullMode = CullMode;

                    GraphicsDevice.RasterizerState = state;

                    // Pass in our Lighting Colors
                    SimpleEffect.AmbientLightColor = AmbientColor.ToVector3();
                    SimpleEffect.DiffuseColor      = DiffuseColor.ToVector3();
                    SimpleEffect.EmissiveColor     = EmissiveColor.ToVector3();
                    SimpleEffect.SpecularColor     = SpecularColor.ToVector3();
                    SimpleEffect.SpecularPower     = SpecularPower;

                    // Update the world, view and projection matrices on the basic effect
                    SimpleEffect.World      = World;
                    SimpleEffect.View       = Camera.View;
                    SimpleEffect.Projection = Camera.Projection;

                    // Pass our texture to our graphics device for rendering
                    if (Texture != null)
                    {
                        SimpleEffect.Texture        = Texture;
                        SimpleEffect.TextureEnabled = true;
                    }

                    foreach (EffectPass pass in SimpleEffect.CurrentTechnique.Passes)
                    {
                        pass.Apply();
                        GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, _width * _height, 0, TriangleCount);
                    }
                }
            }
        }