Difference between revisions of "Hello World in XNA 3.0 using spritefont"
esse quam videri
(New page: 1. Create a new XNA Project) |
|||
Line 1: | Line 1: | ||
+ | [[category:XNA Programming]] | ||
+ | [[category:XNA]] | ||
+ | 1. Create a new XNA Project | ||
+ | [[Image:HelloSpriteFont NewProject.png]] | ||
+ | |||
+ | 2. Right Click on the Content Folder and Choose New Item | ||
+ | [[Image:HelloSpriteFont NewItem.png]] | ||
+ | |||
+ | 3. Select SpriteFont. And name your file Kootenay.spritefont | ||
+ | [[Image:HelloSpriteFont NewSpriteFont.png]] | ||
+ | |||
+ | |||
+ | 4. Now we need to add some code to load our new spriteFont. | ||
+ | Add new SpriteFont variable. | ||
+ | |||
+ | <csharp> | ||
+ | SpriteFont spriteFont; //Declare spriteFont | ||
+ | </csharp> | ||
+ | |||
+ | right below the definition of spriteBatch | ||
+ | <csharp> | ||
+ | SpriteBatch spriteBatch; | ||
+ | </csharp> | ||
+ | |||
+ | 5. Initalize the spriteFont viriable in the Load_Contect Method right below the // TODO: use this.Content to load your game content here | ||
+ | |||
+ | <csharp> | ||
+ | |||
+ | // TODO: use this.Content to load your game content here | ||
+ | spriteFont = Content.Load<SpriteFont>("Kootenay"); | ||
+ | </csharp> | ||
− | + | 6. Add code to Draw some text with your new spriteFont. In the Draw method add | |
+ | |||
+ | <csharp> | ||
+ | // TODO: Add your drawing code here | ||
+ | spriteBatch.Begin(); | ||
+ | spriteBatch.DrawString(spriteFont, "Hello XNA!!!", new Vector2(100, 100), Color.Silver); | ||
+ | spriteBatch.End(); | ||
+ | </csharp> |
Revision as of 20:13, 25 January 2009
2. Right Click on the Content Folder and Choose New Item
3. Select SpriteFont. And name your file Kootenay.spritefont
4. Now we need to add some code to load our new spriteFont.
Add new SpriteFont variable.
<csharp> SpriteFont spriteFont; //Declare spriteFont </csharp>
right below the definition of spriteBatch <csharp> SpriteBatch spriteBatch; </csharp>
5. Initalize the spriteFont viriable in the Load_Contect Method right below the // TODO: use this.Content to load your game content here
<csharp>
// TODO: use this.Content to load your game content here spriteFont = Content.Load<SpriteFont>("Kootenay");
</csharp>
6. Add code to Draw some text with your new spriteFont. In the Draw method add
<csharp>
// TODO: Add your drawing code here spriteBatch.Begin(); spriteBatch.DrawString(spriteFont, "Hello XNA!!!", new Vector2(100, 100), Color.Silver); spriteBatch.End();
</csharp>