Asteroids.Background.Draw C# (CSharp) Метод

Draw() публичный Метод

public Draw ( SpriteBatch spriteBatch ) : void
spriteBatch Microsoft.Xna.Framework.Graphics.SpriteBatch
Результат void
        public void Draw(SpriteBatch spriteBatch)
        {
            Random rnd = new Random();

            foreach (Star star in starArray)
            {
                int random = rnd.Next(0, 1000);

                if (random == 1)
                {
                    star.Draw(spriteBatch, Color.Cyan);
                }
                else if(random == 2)
                {
                    star.Draw(spriteBatch, Color.LightGray);
                }
                else if(random == 3)
                {
                    star.Draw(spriteBatch, Color.White);
                }
                else
                {
                    star.Draw(spriteBatch, Color.Gray);
                }
            }

            foreach (Planet planet in planetArray)
            {
                planet.Draw(spriteBatch, Color.Gray);
            }
        }

Usage Example

Пример #1
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            spriteBatch.Begin();
            background.Draw(spriteBatch);
            spriteBatch.End();


            spriteBatch.Begin();
            bullets.Draw(spriteBatch);
            asteroids.Draw(spriteBatch);
            player.Draw(spriteBatch);
            alien.Draw(spriteBatch);
            spriteBatch.End();

            spriteBatch.Begin();
            for (int i = 0; i < lives; i++)
            {
                Sprite life = new Sprite(graphics, player.Image);
                life.Rotation = 0;
                life.size     = 0.1f;
                life.position = new Vector2(10 + (i * 20), graphics.PreferredBackBufferHeight - 50);
                life.Draw(spriteBatch);
            }
            spriteBatch.End();

            if (counter > 0)
            {
                spriteBatch.Begin();
                spriteBatch.DrawString(font, "Wave " + wave, new Vector2(graphics.PreferredBackBufferWidth / 2 - 60, 200), Color.White * 0.7f);
                spriteBatch.End();
                counter--;
            }
            spriteBatch.Begin();
            if (lives < 0)
            {
                spriteBatch.DrawString(font, "GAME OVER!", new Vector2(200, graphics.PreferredBackBufferHeight / 2), Color.White);
            }
            spriteBatch.End();

            base.Draw(gameTime);
        }