2011-02-18 12 views
6

Estoy jugando con XNA y he llegado a la parte en la que necesito cargar una fuente. Bastante fácil ¿no?No se puede cargar un spriteFont en XNA4

Font1 = Content.Load<SpriteFont>("Arial"); 

Es el código que estoy usando para cargar la fuente.

<?xml version="1.0" encoding="utf-8"?> 
<!-- 
This file contains an xml description of a font, and will be read by the XNA 
Framework Content Pipeline. Follow the comments to customize the appearance 
of the font in your game, and to change the characters which are available to draw 
with. 
--> 
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics"> 
    <Asset Type="Graphics:FontDescription"> 

    <!-- 
    Modify this string to change the font that will be imported. 
    --> 
    <FontName>Arial</FontName> 

    <!-- 
    Size is a float value, measured in points. Modify this value to change 
    the size of the font. 
    --> 
    <Size>14</Size> 

    <!-- 
    Spacing is a float value, measured in pixels. Modify this value to change 
    the amount of spacing in between characters. 
    --> 
    <Spacing>0</Spacing> 

    <!-- 
    UseKerning controls the layout of the font. If this value is true, kerning information 
    will be used when placing characters. 
    --> 
    <UseKerning>true</UseKerning> 

    <!-- 
    Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic", 
    and "Bold, Italic", and are case sensitive. 
    --> 
    <Style>Regular</Style> 

    <!-- 
    If you uncomment this line, the default character will be substituted if you draw 
    or measure text that contains characters which were not included in the font. 
    --> 
    <!-- <DefaultCharacter>*</DefaultCharacter> --> 

    <!-- 
    CharacterRegions control what letters are available in the font. Every 
    character from Start to End will be built and made available for drawing. The 
    default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin 
    character set. The characters are ordered according to the Unicode standard. 
    See the documentation for more information. 
    --> 
    <CharacterRegions> 
     <CharacterRegion> 
     <Start>&#32;</Start> 
     <End>&#126;</End> 
     </CharacterRegion> 
    </CharacterRegions> 
    </Asset> 
</XnaContent> 

es el archivo spritefont que estoy usando. está ubicado en Content/Arial.spritefont.

Independientemente de la fuente que elija, no puede cargar esa fuente.

Error loading "Arial". File not found. 

Respuesta

6

El código que has publicado parece bien, siempre va a configurar el directorio raíz de contenido (esta línea es parte de la plantilla por defecto):

Content.RootDirectory = "Content"; 

Y siempre que haya añadido correctamente el archivo .spritefont a su proyecto de contenido y está construyendo correctamente. Compruebe que se está creando un archivo Arial.xnb en el directorio Content junto a su ejecutable (en bin/Debug o bin/Release dependiendo de su objetivo de compilación).

Si aún tiene problemas, intente crear un nuevo proyecto XNA y vea si puede obtener una fuente para eso.

+2

Todo lo publicado es lo que tenía en mi solución ya. Comencé un nuevo proyecto y copié el código y funcionó bien. No estoy seguro de lo que estaba pasando, pero funciona bien ahora. – castis

2

Asegúrese de que su proyecto de contenido se haya agregado como referencia de contenido a su proyecto principal. Haga clic con el botón derecho en su proyecto y seleccione "Agregar referencia de contenido". Luego, simplemente elija los proyectos de contenido enumerados. Esto asegurará que tu contenido sea copiado.

3

por qué no usar SpriteFont Texture, donde tiene todas las letras en una sola imagen. con esto puedes mostrar la fuente que otras computadoras no tienen. Solo recuerde cambiar ContentProcessor a Font Txture después de agregar texturas al proyecto.

SpriteFont Editor

Some Tutorial

+0

¿Problemas de escala? – Lodewijk

+0

El ciclismo puede causar artefactos en la visualización de SpriteFont, pero en ese caso puede crear diferentes tamaños que use en el juego. –

+0

Ten un voto porque funciona. He tenido muchos problemas con esto desde entonces, así que sigue siendo más atractivo. – Lodewijk

Cuestiones relacionadas