MrGravity.Level.Draw C# (CSharp) Méthode

Draw() public méthode

Draws the level background on to the screen
public Draw ( SpriteBatch spriteBatch, GameTime gameTime, Matrix scale ) : void
spriteBatch Microsoft.Xna.Framework.Graphics.SpriteBatch Sprite batch that we use to draw textures
gameTime Microsoft.Xna.Framework.GameTime
scale Matrix
Résultat void
        public void Draw(SpriteBatch spriteBatch, GameTime gameTime, Matrix scale)
        {
            /* Cam is used to draw everything except the HUD - SEE BELOW FOR DRAWING HUD */
            spriteBatch.Begin(SpriteSortMode.Immediate,
                BlendState.AlphaBlend,
                SamplerState.LinearClamp,
                DepthStencilState.None,
                RasterizerState.CullCounterClockwise,
                null,
                MCam.get_transformation() * scale);

            for (var i = 0; i < _backGroundParticleCount; i++)// && !IsMainMenu; i++)
                _backgroundParticles[i].Draw(spriteBatch);

            foreach (var trigger in _mTrigger)
                trigger.Draw(spriteBatch, gameTime);

            // Loops through all rail objects and draws the appropriate rail image.
            #region DrawRails
            foreach (var rail in _mRails)
            {
                var position = new Vector2(rail.MLocation.X * 64, rail.MLocation.Y * 64);
                var length = Convert.ToInt32(rail.MProperties["Length"]);
                var type = rail.MProperties["Rail"];
                var width = _mRailTop.Width;
                var height = _mRailTop.Height;

                for (var i = 0; i <= length; i++)
                {
                    if (type == "X")
                    {
                        if (i == 0)
                            spriteBatch.Draw(_mRailLeft, new Rectangle(Convert.ToInt32(position.X) + (i*64), Convert.ToInt32(position.Y), width, height), Color.White);
                        else if (i == length)
                            spriteBatch.Draw(_mRailRight, new Rectangle(Convert.ToInt32(position.X) + (i*64), Convert.ToInt32(position.Y), width, height), Color.White);
                        else
                            spriteBatch.Draw(_mRailHor, new Rectangle(Convert.ToInt32(position.X) + (i*64), Convert.ToInt32(position.Y), width, height), Color.White);
                    }
                    else
                    {
                        if (i == 0)
                            spriteBatch.Draw(_mRailTop, new Rectangle(Convert.ToInt32(position.X), Convert.ToInt32(position.Y) + (i*64), width, height), Color.White);
                        else if (i == length)
                            spriteBatch.Draw(_mRailBottom, new Rectangle(Convert.ToInt32(position.X), Convert.ToInt32(position.Y) + (i * 64), width, height), Color.White);
                        else
                            spriteBatch.Draw(_mRailVert, new Rectangle(Convert.ToInt32(position.X), Convert.ToInt32(position.Y) + (i * 64), width, height), Color.White); ;
                    }
                }
            }
            #endregion

            if (_mDeathState == DeathStates.Playing)
            {
                _collectibleEngine.Draw(spriteBatch);
                _wallEngine.Draw(spriteBatch);
            }

            //Draw all of our game objects
            foreach (var gObject in _mObjects)
            {
                if (gObject.CollisionType == XmlKeys.Hazardous)
                {
                    if (gObject is ReverseTile)
                    {
                        if (_mReverseHazardAnimation != null)
                        {
                            _mReverseHazardAnimation.Draw(spriteBatch, gObject.MPosition);
                        }
                    }
                    else if (gObject is MovingTile)
                    {
                        if (_mHazardAnimation != null)
                        {
                            _mHazardAnimation.Draw(spriteBatch, gObject.MPosition);
                        }
                    }
                    else
                    {
                        gObject.Draw(spriteBatch, gameTime);
                    }
                }
                else if (gObject.CollisionType != XmlKeys.Collectable)
                    gObject.Draw(spriteBatch, gameTime);

            }

            //Draw all of our active animations
            if (_shouldAnimate)
            {
                for (var i = 0; i < _mActiveAnimations.Count; i++)
                    _mActiveAnimations.ElementAt(i).Value.Draw(spriteBatch, _mActiveAnimations.ElementAt(i).Key);

                if (_mCollectableAnimation != null)
                {
                    for (var i = 0; i < _mCollectableLocations.Count; i++)
                    {
                        _mCollectableAnimation.Draw(spriteBatch, _mCollectableLocations.ElementAt(i));
                    }
                }

            }

            spriteBatch.End();
        }