在XNA 4.0 3D中绘制字符串和纹理? [英] Draw String and Texture in XNA 4.0 3D ?
问题描述
在XNA 4.0 3D中绘制字符串时遇到问题,我知道的问题是spriteBatch.Begin().但是我不知道该怎么解决.
I have problem when I draw a string in XNA 4.0 3D.I known problem is spriteBatch.Begin(). But I don''t know how to solve it.
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.DeepSkyBlue);
//Draw string
spriteBatch.Begin();
spriteBatch.DrawString(fontArial, "Demotesting", new Vector2(100, 100), Color.Red);
spriteBatch.End();
//Draw Models Ship
ship.Draw();
base.Draw(gameTime);
}
画线之前:
< img src ="http://nq1.upanh.com/b4.s32.d1/6c6ce19bded8d054341ce45e17426c51_49358001.before. png"/>
拔弦后
< img src ="http://nq2.upanh.com/b6.s30.d2/9ff7c3c009215348b06a53c5a067d282_49358002.after. png"/>
能帮帮我吗?
P/S:对不起,因为英语不好!
Before draw string:
<img src="http://nq1.upanh.com/b4.s32.d1/6c6ce19bded8d054341ce45e17426c51_49358001.before.png" />
After draw string
<img src="http://nq2.upanh.com/b6.s30.d2/9ff7c3c009215348b06a53c5a067d282_49358002.after.png" />
Can help me?
P/S:Sorry because bad english!
推荐答案
您需要做两件事.
第一的.在2D之前绘制3D
You need to do two things.
First. draw 3D before 2D
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.DeepSkyBlue);
//Reset Graphics Device here
#region 3D
//Draw Models Ship
ship.Draw();
#endregion
#region 2D
//Draw string
spriteBatch.Begin();
spriteBatch.DrawString(fontArial, "Demotesting", new Vector2(100, 100), Color.Red);
spriteBatch.End();
#endregion
base.Draw(gameTime);
}
其次,您应该确保将图形设计重置为默认的模型渲染 ^ ]
Second you should ensure that you are resetting the graphics devise to the default for model rendering See Here[^]
感谢ely_bob为您的答案!但我认为
Thanks ely_bob for your answer! But I think
GraphicsDevice.SamplerStates [0] = SamplerState.AnisotropicWrap;
比
好
is better than
GraphicsDevice.SamplerStates [0] = SamplerState.LinearClamp;
这篇关于在XNA 4.0 3D中绘制字符串和纹理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!