Click here to Skip to main content
15,794,275 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
See,I have this code-
if (RunsCollision.isrunnew == true)
           { i = 0;

               i += 0.1f;
               Game1.spriteBatch.DrawString(Game1.scorefont, runstoshow, new Vector2(200, 200), color);
           } while (i < 100);
           RunsCollision.isrunnew = false;

when I run this code in my Draw() method,the text appears for only about 1 second.I want the text to be displayed for 5 seconds.I have tried changing the values but still no luck.
Please help me fir my school project.Its urgent.
Updated 18-Apr-16 5:08am
[no name] 11-Oct-14 15:03pm    
What changes have you made? Have you tried debugging your code to see what line of code removes your sprite string?

1 solution

I know this is very late, but in case anyone reads this, or if you haven't figured it out yet; you should not be handling the timer in your draw routine. You're basically trying to sleep the thread here with your while loop. What would be more appropriate is using the Update() method which gives you access to the gameTime and check for gameTime.ellapsedGameTime.totalmilliseconds. In the Update() method you will also be checking collisions, if you need to start timing something like this SpriteFont after a collision, you should have a bool that draw routine has access to that you will mark true/false from within the Update() method when you want the SpriteFont to be drawn.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900