Hi everyone,
I'm working on a project that uses DirectX and C#, and untill now I had no problems. I have encountered some very strange behavior with Direct3D.Font.DrawText method. Internally I use the same sprite object for drawing sprites and for text.
Excluding other parameters, you must pass XY coordinates or a rectangle that represents the position of the text. So if I pass the new Rectangle(0,0,100,100) the text would be positioned on the top-left of the screen inside the rectangle.
Well, it isnt. Its positioned relative to the
last sprite drawn with the sprite object.
Here is the text drawing code:
public static void DrawText(string text, string font, Rectangle position, int color)
{
if (true == m_FontCollection.ContainsKey(font))
{
m_FontCollection[font].DrawText(m_sprSprite, text, position, Direct3D.DrawTextFormat.WordBreak, color);
}
else
{
Log.Write("DrawText: Font '" + font + "' was not loaded.");
Engine.Exit(true);
}
}
Here the sprite drawin routine:
public static void Draw2D(Sprite s)
{
try
{
m_sprSprite.Draw2D(s.GetTexture(), s.GetSrcRect(), s.GetSize(), s.GetCenter(), s.GetRotation(), s.GetPosition(), s.GetColor());
}
catch (Exception e)
{
Log.Write(e);
throw e;
}
}
So what happens is that when I draw just the text, it is positioned just fine, but if I draw a sprite and then some text, the text is positioned relative to the last sprite drawn position. Can't figure this one out...
[Edited by - dejangex on March 2, 2008 4:29:28 AM]