Category Archives: xna

XNA Tutorial 1: Hello world


Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /homepages/30/d572126800/htdocs/web/elvenprogrammer.org/wordpress/wp-content/plugins/wp-syntax/wp-syntax.php on line 383

Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /homepages/30/d572126800/htdocs/web/elvenprogrammer.org/wordpress/wp-content/plugins/wp-syntax/wp-syntax.php on line 383

Start XNA Game studio and create a new Windows game project.

Right click Content folder and choose Add, New Item.
Select Sprite Font and rename it to some font you like, such as “Arial”.

You can now open the file and modify some of the options such as Size or Style.

Locate the following code:

protected override void Draw(GameTime gameTime)
{
    GraphicsDevice.Clear(Color.CornflowerBlue);
 
    // TODO: Add your drawing code here
 
    base.Draw(gameTime);
}

[ad]

And finally add the code to draw a string:

spriteBatch.Begin();
 
spriteBatch.DrawString(Content.Load<SpriteFont>("Arial"), "Hello world", new Vector2(100, 100), Color.Black);
 
spriteBatch.End();

[ad]

Easy, isn’t it?