Created
July 26, 2014 16:17
-
-
Save flibitijibibo/e1e9dedd7f08de2f8581 to your computer and use it in GitHub Desktop.
SpriteFont Accuracy Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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