// 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.


1 Answer 1


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

  • \$\begingroup\$ Why do they multiply the time by 6 ? \$\endgroup\$
    – Setheron
    Apr 27, 2012 at 17:07
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – House
    Apr 27, 2012 at 17:08
  • \$\begingroup\$ How can I relate it to the frequency? \$\endgroup\$
    – Setheron
    Apr 27, 2012 at 17:15
  • 1
    \$\begingroup\$ @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. \$\endgroup\$
    – Eric
    Apr 27, 2012 at 17:20
  • 2
    \$\begingroup\$ @Setheron: A pulse every ~1.05 seconds is slightly less. :-) \$\endgroup\$
    – Eric
    Apr 27, 2012 at 18:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .