Spritebatch not working in winforms
Posted
by
CodingMadeEasy
on Game Development
See other posts from Game Development
or by CodingMadeEasy
Published on 2013-09-20T03:34:29Z
Indexed on
2013/10/20
16:12 UTC
Read the original article
Hit count: 893
I'm using the Winforms sample on the app hub and everything is working fine except my spritebatch won't draw anything unless I call Invalidate in the Draw method. I have this in my initialize method:
Application.Idle += delegate { Invalidate(); };
I used a breakpoint and it is indeed invalidating my program and it is calling my draw method. I get no errors with the spritebatch and all the textures are loaded I just don't see anything on the screen. Here's the code I have:
protected override void Draw()
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
tileSheet.Draw(spriteBatch);
foreach (Image img in selector)
img.Draw(spriteBatch);
spriteBatch.End();
}
But when I do this:
protected override void Draw()
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
tileSheet.Draw(spriteBatch);
foreach (Image img in selector)
img.Draw(spriteBatch);
spriteBatch.End();
Invalidate();
}
then all of a sudden the drawing starts to work! but the problem is that it freezes everything else and only that control gets updated. What can I do to fix this? It's really frustrating.
© Game Development or respective owner