XNA Creators Club Online
Page 1 of 1 (6 items)
Sort Posts: Previous Next

Thread.Sleep causing SpriteBatch to not draw

Last post 05-13-2008 7:45 AM by Bjoern Graf. 5 replies.
  • 05-12-2008 11:43 PM

    Thread.Sleep causing SpriteBatch to not draw

    Well I have a class to handle all the UI tasks. Now I want to have a splash screen. So I made a pic and added it to my Content folder. I have an automated void to do everything for me below. But when the sprite draws all I get is a white square, but if I take out Thread.Sleep it draws fine. How can I get the SpriteBatch to fully draw befor Thread.Sleep?

    public void Draw()
            {
                //Draw the Splash
                DrawSplash();
                //Sleep
                Thread.Sleep(1000);
                //Restore
                Graphics.Clear(Color.CornflowerBlue);
            }

  • 05-13-2008 12:08 AM In reply to

    Re: Thread.Sleep causing SpriteBatch to not draw

    Make sure you are drawing that splash spritebatch with immediate sort mode.
    Michael Coles
    Senior Programmer
    Digini Inc.
    http://www.blade3d.com
  • 05-13-2008 12:09 AM In reply to

    Re: Thread.Sleep causing SpriteBatch to not draw

    Thread.Sleep is not what you want to be doing inside of a game loop. To have a splash screen display for a certain amount of time, you should be using the GameTime object that is passed in to the Update and Draw methods and a splash screen tracking variable.

    Then everytime Update is called, decrement that variable. When it is below zero, then don't display the Splash screen any longer. You might also want to explore the concept of GameState a little further. Since what you really want to do is have your game in a "Splash Screen" state for a certain amount of time.

    But pausing your game loop, never a good idea.
  • 05-13-2008 5:18 AM In reply to

    Re: Thread.Sleep causing SpriteBatch to not draw

    I agree with what's been said above, you seem to misunderstand how the graphics card and the API work. Just because you've called draw, doesn't mean that it's on the screen, nothing gets drawn *at all* until Present is called in EndDraw, which you should just think of as "the end of the draw method". All calling draw does is setting up a queue of draw calls that will have no visual impact until 2-3 frames later. Do what George suggested and start a timer as 1 second, decrement time as it passes, and when it reaches zero, stop drawing the splash. The way you're doing it currently is just never going to work.
  • 05-13-2008 6:42 AM In reply to

    Re: Thread.Sleep causing SpriteBatch to not draw

    I third that. Also if the splash screen is going to show any longer, it may be a good time to load anything on a bg thread while its showing.
    Michael Coles
    Senior Programmer
    Digini Inc.
    http://www.blade3d.com
  • 05-13-2008 7:45 AM In reply to

    Re: Thread.Sleep causing SpriteBatch to not draw

    For completeness I would like to link to the Game State Management Sample on this very site.
    We are boki. The rest is known.
    The not so known part of the rest: It is Björn or Bjoern, but never Bjorn.
    Vote: Allow use of non-ASCII characters in names and titles
Page 1 of 1 (6 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG