All pastes #457104 Raw Edit

Miscellany

public text v1 · immutable
#457104 ·published 2007-04-25 05:22 UTC
rendered paste body
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;

public class Game1 : Microsoft.Xna.Framework.Game
{
    GraphicsDeviceManager graphics;
    ContentManager content;



    public Game1()
    {
        graphics = new GraphicsDeviceManager(this);
        content = new ContentManager(Services);
    }


    protected override void Initialize()
    {
        base.Initialize();
    }


    SpriteBatch ForegroundBatch;
    SpriteFont Arial;
    Vector2 FontPos;
    float FontRotation;
    protected override void LoadGraphicsContent(bool loadAllContent)
    {
        if (loadAllContent)
        {
            Arial = content.Load<SpriteFont>("Arial");
            ForegroundBatch = new SpriteBatch(graphics.GraphicsDevice);
        }
        FontPos = new Vector2(graphics.GraphicsDevice.Viewport.Width / 2,
            graphics.GraphicsDevice.Viewport.Height / 2);
        FontRotation = 0;
    }


    protected override void UnloadGraphicsContent(bool unloadAllContent)
    {
        if (unloadAllContent)
        {
            content.Unload();
        }
    }

    protected override void Update(GameTime gameTime)
    {
        base.Update(gameTime);
    }

    protected override void Draw(GameTime gameTime)
    {
        graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

        ForegroundBatch.Begin();

        // Draw Hello World
        string output = "Hello World";

        // Find the center of the string
        Vector2 FontOrigin = Arial.MeasureString(output) / 2;
        // Draw the string
        ForegroundBatch.DrawString(Arial, output, FontPos, Color.LightGreen,
            FontRotation, FontOrigin, 1.0f, SpriteEffects.None, 0.5f);
        //Note: Change "CourierNew" to "current" above to enable switching

        // Draw instructions
        Vector2 guidepos = new Vector2(50, FontPos.Y + 100);
        string guide = "Right Thumbstick: Rotate\nA, B, X Buttons: Change Font";
        ForegroundBatch.DrawString(Arial, guide, guidepos, Color.Black);

        ForegroundBatch.End();
        base.Draw(gameTime);
    }
}