Difference between revisions of "Hello World in XNA 3.0 using spritefont"

esse quam videri
Jump to: navigation, search
m (Text replacement - "syntaxhighlight lang="csharp" line="1" " to "syntaxhighlight lang="csharp"")
 
(3 intermediate revisions by the same user not shown)
Line 16: Line 16:
 
Add new SpriteFont variable.
 
Add new SpriteFont variable.
  
<csharp>
+
<syntaxhighlight lang="csharp">
 
SpriteFont spriteFont;      //Declare spriteFont
 
SpriteFont spriteFont;      //Declare spriteFont
</csharp>
+
</syntaxhighlight>
  
 
right below the definition of spriteBatch
 
right below the definition of spriteBatch
<csharp>
+
<syntaxhighlight lang="csharp">
 
SpriteBatch spriteBatch;
 
SpriteBatch spriteBatch;
</csharp>
+
</syntaxhighlight>
  
5. Initalize the spriteFont viriable in the Load_Contect Method right below the // TODO: use this.Content to load your game content here
+
5. Initalize the spriteFont viriable in the Load_Content() Method right below the // TODO: use this.Content to load your game content here
  
<csharp>
+
<syntaxhighlight lang="csharp">
  
 
             // TODO: use this.Content to load your game content here
 
             // TODO: use this.Content to load your game content here
 
             spriteFont = Content.Load<SpriteFont>("Kootenay");
 
             spriteFont = Content.Load<SpriteFont>("Kootenay");
</csharp>
+
</syntaxhighlight>
  
6. Add code to Draw some text with your new spriteFont. In the Draw method add
+
6. Add code to Draw some text with your new spriteFont. In the Draw() method add
  
<csharp>
+
<syntaxhighlight lang="csharp">
 
  // TODO: Add your drawing code here
 
  // TODO: Add your drawing code here
 
             spriteBatch.Begin();
 
             spriteBatch.Begin();
 
             spriteBatch.DrawString(spriteFont, "Hello XNA!!!", new Vector2(100, 100), Color.Silver);
 
             spriteBatch.DrawString(spriteFont, "Hello XNA!!!", new Vector2(100, 100), Color.Silver);
 
             spriteBatch.End();
 
             spriteBatch.End();
</csharp>
+
</syntaxhighlight>

Latest revision as of 03:21, 9 February 2016

1. Create a new XNA Project

HelloSpriteFont NewProject.png

2. Right Click on the Content Folder and Choose New Item

HelloSpriteFont NewItem.png

3. Select SpriteFont. And name your file Kootenay.spritefont

HelloSpriteFont NewSpriteFont.png

4. Now we need to add some code to load our new spriteFont. Add new SpriteFont variable.

SpriteFont spriteFont;      //Declare spriteFont

right below the definition of spriteBatch

SpriteBatch spriteBatch;

5. Initalize the spriteFont viriable in the Load_Content() Method right below the // TODO: use this.Content to load your game content here

            // TODO: use this.Content to load your game content here
            spriteFont = Content.Load<SpriteFont>("Kootenay");

6. Add code to Draw some text with your new spriteFont. In the Draw() method add

 // TODO: Add your drawing code here
            spriteBatch.Begin();
            spriteBatch.DrawString(spriteFont, "Hello XNA!!!", new Vector2(100, 100), Color.Silver);
            spriteBatch.End();