Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
// Pulsate the size of the selected menu entry.
double time = gametime.TotalGameTime.TotalSeconds;
float pulsate = (float)Math.Sin(time * 6) + 1;
scale = new Scale(1 + pulsate * 0.05f,1 + pulsate * 0.05f);

I grabbed it from the XNA GameState sample and just curious.

share|improve this question
up vote 5 down vote accepted

Looks like it's using a sine wave to change the scale of an object. Sine ranges from -1 to +1, so adding one to the pulsate variable puts the range at 0 to 2. Then adding 1 to (pulstae * 0.05f) Puts the range at 1 to 1.10.

As the name implies, this would likely give the appearance of pulsating.

Multiplying the time by 6 compresses the sine wave on the x-axis. Making the pulsing happen faster. If you were to multiply it by a smaller number (or not multiply it by anything) you could slow the pulsing.

sine wave

share|improve this answer
Why do they multiply the time by 6 ? – Setheron Apr 27 '12 at 17:07
Multiplying the time by 6 will change the speed at which the pulsing happens. Basically it shrinks the sine wave on the x axis. Pulsing faster. – Byte56 Apr 27 '12 at 17:08
How can I relate it to the frequency? – Setheron Apr 27 '12 at 17:15
@Setheron: No, sin(t)'s period is 2PI seconds, so sin(6*t) gives you a pulse every 2PI/6 seconds, which is slightly less often than once a second. – Eric Apr 27 '12 at 17:20
@Setheron: A pulse every ~1.05 seconds is slightly less. :-) – Eric Apr 27 '12 at 18:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.