The basic game framework XNA developed by Microsoft is used to make games on all their current platforms, such as Windows and Xbox. XNA is designed to work with the programming language C# in Visual Studio. Users can use free express or paid professional versions of XNA. Both versions support all code and programming, including spritefonts. A spritefont is the framework's way of handling text drawn onto the screen or an image.
- Skill level:
Other People Are Reading
Things you need
- XNA software
- C# software
Open C# Express by clicking "File" and "New Project." Select the version of XNA to use such as XNA 4.0, and select "Windows Game" in the form. Name the project and choose the project directory then click "Create." This will create a game template with all the libraries and basic structure pre-made.
Create your variables. Put the code in the "game1" class near the top of the input screen. This will allow you to find them easier and let all functions access them.
String message = "Hello!";
Load the font, but first you will need to add it to your project. Look for the "Project Directory Listing" on the edge of the window. Right-click on the "Content Directory" and select "Add Item." A new window will pop up. Choose "Sprite Font." The default name is "SpriteFont1.spritefont." Select "OK." This will bring up an XML document. You should see the tags "<FontName>Kootaney</FontName>" in the XML. The middle is the system font to be used. You can change it to "Arial," for example, by replacing "Kootaney" with "Arial."
Go back to the "Game1.cs" tab and scroll down to the "LoadContent()" function. You will need to add the following code to load the spritefont:
"MessageFont = Content.Load<SpriteFont>("Content/SpriteFont1");"
Scroll down to the function "Draw()" and in between the two lines of code already there, add the following code:
spriteBatch.Begin(); spriteBatch.DrawString(MessageFont, message, new Vector 2(20, 20), Color.Gold); spriteBatch.End();
Push "f6" to build the project. Press "f5" to test your file. A window will pop up displaying the word, "Hello!" You can change this message by replacing the "Hello!" in the variables code at the top of the screen with whatever text you want.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for