Difference between revisions of "Using SpriteFont"
m |
|||
(4 intermediate revisions by one other user not shown) | |||
Line 15: | Line 15: | ||
Select SpriteFont, and make sure you enter a name for your new SpriteFont. | Select SpriteFont, and make sure you enter a name for your new SpriteFont. | ||
− | + | Your new SpriteFont will now be displayed in the pipeline: | |
[[File:Spritefontadded.gif]] | [[File:Spritefontadded.gif]] | ||
Line 30: | Line 30: | ||
[[File:Builtpipeline.gif]] | [[File:Builtpipeline.gif]] | ||
+ | |||
+ | Often the pipeline fails to build the spritefonts, so use [https://drive.google.com/file/d/0Bw-0YEA_JX9gM2hGNnBwU203dGM/view?usp=sharing this link to get some pre built fonts]. These need to go in the project folder, Bin, Windows, X86, Debug, and then Content. | ||
+ | |||
+ | The main reason for a build failure concerns a file called 'freetype6.dll', if this is your error it is easily fixed by installing [https://www.microsoft.com/en-us/download/details.aspx?id=30679 This windows update]. | ||
==Using the SpriteFont== | ==Using the SpriteFont== | ||
Line 52: | Line 56: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | It must go between | + | It must go between a SpriteBatch.Begin() and a SpriteBatch.End(). |
Latest revision as of 13:54, 25 November 2020
Contents
Open the Content Pipeline
Double click the Content.MGCB file within the project solution explorer:
this will open the Content Pipeline:
Add New Item
Click the add new item icon, you will then see the following options:
Select SpriteFont, and make sure you enter a name for your new SpriteFont.
Your new SpriteFont will now be displayed in the pipeline:
Changing the font options
You will need to browse to your project content folder and edit the created file:
The file is XML, and you can clearly see the options currently set, the above image shows the current font. You can simply change the current value for another font. The same is true for the other values in the file such as size, the style section even gives you pointers.
Build the pipeline
You now need to click the build button to create the appropriate XNB files:
Often the pipeline fails to build the spritefonts, so use this link to get some pre built fonts. These need to go in the project folder, Bin, Windows, X86, Debug, and then Content.
The main reason for a build failure concerns a file called 'freetype6.dll', if this is your error it is easily fixed by installing This windows update.
Using the SpriteFont
Add the following variables to your other definitions:
private SpriteFont font;
private int score = 0;
Now in the LoadContent section you need to load the SpriteFont:
font = Content.Load<SpriteFont>("Example");
If you get a content not found error, copy the XNB file from the content folder into the project bin/debug/content folder.
Now in the Draw method add the following to draw the text to the screen:
spriteBatch.DrawString(font, "Score", new Vector2(100, 100), Color.Black);
It must go between a SpriteBatch.Begin() and a SpriteBatch.End().