Beispiel #1
0
        private void OnDraw(object sender, GameTimerEventArgs e)
        {
            if (isActive)
            {
                // Draw the Silverlight UI into the texture
                //if (elementRenderer != null)
                //    elementRenderer.Render();
                try
                {
                    if (elementRenderer != null)
                    {
                        // Draw the Silverlight UI into the texture
                        elementRenderer.Render();
                    }
                }
                catch (ObjectDisposedException)
                {
                    CreateUiElementRenderer();
                }


                //SharedGraphicsDeviceManager.Current.GraphicsDevice.Clear(Color.CornflowerBlue);
                SharedGraphicsDeviceManager.Current.GraphicsDevice.Clear(Microsoft.Xna.Framework.Color.Black);

                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive);

                particleSystem.Draw(spriteBatch, 1, Vector2.Zero);

                spriteBatch.End();

                spriteBatch.Begin();

                // Using the texture from the UIElementRenderer,
                // draw the Silverlight controls to the screen.
                spriteBatch.Draw(elementRenderer.Texture, Vector2.Zero, Microsoft.Xna.Framework.Color.White);

                spriteBatch.End();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Allows the page to draw itself.
        /// </summary>
        private void OnDraw(object sender, GameTimerEventArgs e)
        {
            try
            {
                if (elementRenderer != null)
                {
                    // Draw the Silverlight UI into the texture
                    elementRenderer.Render();
                }
            }
            catch (ObjectDisposedException)
            {
                CreateUiElementRenderer();
            }


            //SharedGraphicsDeviceManager.Current.GraphicsDevice.Clear(Color.CornflowerBlue);
            SharedGraphicsDeviceManager.Current.GraphicsDevice.Clear(Color.Black);

            // TODO: Add your drawing code here
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive);

            particleSystem.Draw(spriteBatch, 1, Vector2.Zero);

            spriteBatch.End();

            spriteBatch.Begin();

            if (isGameOver == false)
            {
                foreach (var laserBullet in bullets)
                {
                    laserBullet.Draw(spriteBatch);
                }

                foreach (var item in enemies)
                {
                    item.Draw(spriteBatch);
                }

                player.Draw(spriteBatch);

                // Using the texture from the UIElementRenderer,
                // draw the Silverlight controls to the screen.
                spriteBatch.Draw(elementRenderer.Texture, Vector2.Zero, Color.White);

                Vector2 scorePosition = new Vector2(600, playerYposition + 20);
                spriteBatch.DrawString(font, score.ToString(), scorePosition, Color.Gray);
                scorePosition.Y += 2;
                spriteBatch.DrawString(font, score.ToString(), scorePosition, Color.Red);
            }
            else
            {
                Vector2 scorePosition = new Vector2(centerX - font.MeasureString(score.ToString()).X / 2, 260);
                spriteBatch.DrawString(font, score.ToString(), scorePosition, Color.Red);
                scorePosition.Y += 2;
                scorePosition.X += 1;
                spriteBatch.DrawString(font, score.ToString(), scorePosition, Color.WhiteSmoke);

                endGameScore.Draw(spriteBatch);
            }

            spriteBatch.End();
        }