XNA中的字体问题 [英] Problems with font in XNA
问题描述
我正在尝试在XNA中制作一些游戏,但我遇到以下问题:
当我加载并在屏幕上显示3D模型时,一切都好。你可以在这张照片上看到它:
Img1
但是当我向我的程序添加字体时
I''m trying to make some games in XNA, but I have the following problem:
When I load and show the 3d model on the screen, there is everything ok. You can see it on this picture:
Img1
But when I add a font to my program
font1 = Content.Load<SpriteFont>("Fonts/Fon1");
并显示一些文字
and show some text
spriteBatch.Begin();
spriteBatch.DrawString(font1, "Speed: ", new Vector2(5, 5), Color.Red);
spriteBatch.End();
我突然得到那个结果
Img2
为什么第二张图片中的模型是透明的?
是否有任何属性在显示2D精灵时以某种方式使模型透明?
请帮助。
I suddenly get that result
Img2
Why is my model in the second image transparent?
Is there any property that somehow makes models transparent when displaying 2D sprites?
Please help.
推荐答案
我在GraphicsDevice中找不到RenderState属性,但我发现了这个:
I could not find the RenderState property inside GraphicsDevice, but I found this:
GraphicsDevice.BlendState = BlendState.Opaque;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
该网站上的
: http://blogs.msdn.com/b /shawnhar/archive/2010/06/18/spritebatch-and-renderstates-in-xna-game-studio-4-0.aspx [ ^ ]
非常感谢你的帮助!
on that site: http://blogs.msdn.com/b/shawnhar/archive/2010/06/18/spritebatch-and-renderstates-in-xna-game-studio-4-0.aspx[^]
Thanks you very much for your help!
好的,我试着找到你为什么这么做,看看这篇文章: XNA奇怪的3D绘画它似乎是同样的问题,用spritebatch绘制后呈现状态问题
更改此attribut e使用spritebatch后
Ok, I tried to find why you got that, take a look at this post : XNA weird 3D painting It''s seems to be the same problem, a render state problem after drawing with spritebatch
Change this attribute after using spritebatch
GraphicsDevice.RenderState.DepthBufferEnable = true;
这篇关于XNA中的字体问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!