Domanda

I just found something that caught my interest. See, I usually do my "timers" with an int Time = Duration; and in my update it would go Time -= gameTime.ElapsedGameTime.MilliSeconds;. However, I just tried to do it with gameTime.ElapsedGameTime.Seconds instead, since I thought it would be more performance-friendly. But now it isn't updating at all!

My code is basically:

Declaring variables: int Time = 120; SpriteFont spriteFont1;

Updating: Time -= gameTime.ElapsedGameTime.Seconds;

Drawing a string to tell me the time: spriteBatch.Draw(Time, Position, Color.White)

Somehow, the string only tells me that the time is decreasing when I'm doing it with MilliSeconds, not Seconds. Why?

È stato utile?

Soluzione

gameTime.ElapsedGameTime.Seconds is the amount of time since the last update. Since it updates very fast the time between updates are smaller than seconds. Seconds gets returned as an int so you will always get 0.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top