コード例 #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.Red);


            if (currentScreen == Menu.Play)
            {
                spriteBatch.Begin();
                map.Draw(spriteBatch, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), viewportPosition - new Vector2((graphics.PreferredBackBufferWidth / 2), (graphics.PreferredBackBufferHeight / 2)));
                foreach (var sprite in _sprites)
                {
                    sprite.Draw(spriteBatch, viewportPosition + new Vector2(0, 100) - new Vector2((graphics.PreferredBackBufferWidth / 2), (graphics.PreferredBackBufferHeight / 2)));
                }
                foreach (Enemy sprite in EnemyList)
                {
                    sprite.Draw(spriteBatch, new Vector2(0, 100) - new Vector2((graphics.PreferredBackBufferWidth / 2), (graphics.PreferredBackBufferHeight / 2)), true);
                    //sprite.Draw(spriteBatch, sprite.Position, true);
                }

                spriteBatch.End();
            }
            else
            {
                current.Draw(gameTime);
            }

            // TODO: Add your drawing code here

            base.Draw(gameTime);
        }
コード例 #2
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.SkyBlue);

            // if the game is playing
            if (currentScreen == Menu.Play)
            {
                spriteBatch.Begin();

                // draw map
                map.Draw(spriteBatch, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), viewportPosition - new Vector2((graphics.PreferredBackBufferWidth / 2), (graphics.PreferredBackBufferHeight / 2)));

                // draw the player
                foreach (var sprite in _sprites)
                {
                    sprite.Draw(spriteBatch, viewportPosition + new Vector2(0, 100) - new Vector2((graphics.PreferredBackBufferWidth / 2), (graphics.PreferredBackBufferHeight / 2)));
                }


                // draw each enemy
                foreach (Enemy sprite in EnemyList)
                {
                    sprite.Draw(spriteBatch, viewportPosition + new Vector2(0, 100) - new Vector2((graphics.PreferredBackBufferWidth / 2), (graphics.PreferredBackBufferHeight / 2)), true);
                }
                // draw foreground layers
                map.Layers["DTile Layer 1"].Draw(spriteBatch, map.Tilesets.Values, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), viewportPosition - new Vector2((graphics.PreferredBackBufferWidth / 2), (graphics.PreferredBackBufferHeight / 2)), tilepixel, tilepixel);
                spriteBatch.DrawString(big, " " + "Coins collected: " + (coin_collected), new Vector2(1, 1), Color.Black);
                spriteBatch.DrawString(big, " " + "Coins collected: " + (coin_collected), new Vector2(0, 0), Color.DarkGoldenrod);
                spriteBatch.End();
            }
            else
            {
                // not playing so draw current menu
                spriteBatch.Begin();
                spriteBatch.Draw(menuBackground, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);
                spriteBatch.End();
                current.Draw(gameTime);
            }

            // TODO: Add your drawing code here

            base.Draw(gameTime);
        }