Draw String - textures missing

Topics: Developer Forum, Project Management Forum, User Forum
Feb 25, 2008 at 11:18 PM
Edited Feb 25, 2008 at 11:26 PM
Hi everybody,

I have a little problem with my project and I need urgent help.
I have a project with my own terrain whitch is created from *.bmp file. The terrain have grass texture and everything is pretty fine. But if i want to draw string to display then all textures are "lost" and the terrain is just like colored, no textured, but the text (string) is written good.

for drawing text I used SpriteBatchmySpriteBatch object. And in a jiffy when I begin with spriteBatch.Begin() method all textures are missing.

part of drawing code:

spriteBatch.Begin();

// Define string for drawing
stringoutput="MyString";

// Find the center of the string
Vector2FontOrigin=Font1.MeasureString(output)/2;

// Draw the string
spriteBatch.DrawString(Font1,output,FontPosition,Color.LightGreen,
0,FontOrigin,1.0f,SpriteEffects.None,0.5f);

spriteBatch.End();

Is any choice to draw string or how can i fix that?

thnx a lot.
Feb 26, 2008 at 12:07 AM
Edited Feb 26, 2008 at 12:09 AM
Actually this problem is likely to relate to spritebatch - and not the component library.
Spritebatch messes around with the render states, so the most simple way is to use

spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState);

The last arugment is the important one - using SaveState the SpriteBatch restores modified render states at spriteBatch.End();

When finetuning your code, you would only restore the render states you really need since this gives a performance increase compared to restoring all render states.