Xna 将缺少的字符替换为“?”&引用;性格

Xna 将缺少的字符替换为“?”&引用;性格,xna,spritefont,Xna,Spritefont,有没有一种简单的方法可以使默认XNA方法SpriteBatch.DrawString用符号替换spritefont中不存在的字符?我可以使用扩展方法,但我不确定如何实现它,因为事先无法知道字符是否不在spritefont中。此功能是内置的。打开您字体的.spritefont文件并向下滚动至此处: <!-- If you uncomment this line, the default character will be substituted if you draw or measure

有没有一种简单的方法可以使默认XNA方法
SpriteBatch.DrawString
符号替换spritefont中不存在的字符?我可以使用扩展方法,但我不确定如何实现它,因为事先无法知道字符是否不在spritefont中。

此功能是内置的。打开您字体的
.spritefont
文件并向下滚动至此处:

<!--
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> -->

取消对该行的注释并用所需字符替换该字符,如下所示:

<DefaultCharacter>?</DefaultCharacter>
您还可以通过在运行时修改
SpriteFont.DefaultCharacter
属性来实现相同的效果

如果需要,可以通过
SpriteFont.characters
属性获取字体中可用字符的列表