Fri
21
Sep '07
This is a quick sample which demonstates the loading of texture and output of a string.
No worries, 99% of the code is already supplied by Visual Studio
No worries, 99% of the code is already supplied by Visual Studio
#region Using Statements
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;
#endregion
namespace WindowsGame1
{
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()
{
// TODO: Add your initialization logic here
base.Initialize();
}
protected override void LoadGraphicsContent(bool loadAllContent)
{
if (loadAllContent)
{
}
}
protected override void UnloadGraphicsContent(bool unloadAllContent)
{
if (unloadAllContent)
{
content.Unload();
}
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
string str = “Hello”;
SpriteBatch f = new SpriteBatch(graphics.GraphicsDevice);
SpriteFont font = content.Load<spritefont>(“Arial”);
Vector2 fo = font.MeasureString(str)/2;
Texture2D texture = content.Load<texture2d>(“mysprite”);
f.Begin();
f.Draw(texture, fo, Color.Blue);
f.DrawString(font, str, fo, Color.Red);
f.End();
base.Draw(gameTime);
}
}
}
</texture2d></spritefont>

Leave a passing comment »