Skip to content

Instantly share code, notes, and snippets.

@flibitijibibo
Created July 26, 2014 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flibitijibibo/e1e9dedd7f08de2f8581 to your computer and use it in GitHub Desktop.
Save flibitijibibo/e1e9dedd7f08de2f8581 to your computer and use it in GitHub Desktop.
SpriteFont Accuracy Test
/* SpriteFont Accuracy Test
* Written by Ethan "flibitijibibo" Lee
* http://www.flibitijibibo.com/
*
* Released under public domain.
* No warranty implied; use at your own risk.
*/
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
class SpriteFontTest : Game
{
private const string text = "Here's one line.\nHey, another!";
private static readonly Vector2[] positions = new Vector2[]
{
new Vector2(50.0f, 200.0f),
new Vector2(225.0f, 200.0f),
new Vector2(400.0f, 200.0f),
new Vector2(575.0f, 200.0f)
};
private static readonly Color[] colors = new Color[]
{
Color.White,
Color.Red,
Color.Blue,
Color.Yellow
};
private SpriteFont font;
private SpriteBatch batch;
private float rotation;
public SpriteFontTest() : base()
{
new GraphicsDeviceManager(this);
rotation = 0.0f;
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
batch.Begin();
for (int i = 0; i < 4; i += 1)
{
batch.DrawString(
font,
text,
positions[i],
colors[i],
rotation,
Vector2.Zero,
1.0f,
(SpriteEffects) i,
0.0f
);
}
batch.End();
}
protected override void Update(GameTime gameTime)
{
if (Keyboard.GetState().IsKeyDown(Keys.Down))
{
rotation += 0.1f;
}
else if (Keyboard.GetState().IsKeyDown(Keys.Up))
{
rotation -= 0.1f;
}
}
protected override void LoadContent()
{
font = Content.Load<SpriteFont>("NewSerif");
batch = new SpriteBatch(GraphicsDevice);
}
protected override void UnloadContent()
{
batch.Dispose();
batch = null;
font = null; // FIXME: How do we Dispose...?
}
public static void Main(string[] args)
{
using (SpriteFontTest game = new SpriteFontTest())
{
game.Run();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment