Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.
// 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

1 Answer 1

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
1  
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
1  
@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
2  
@Setheron: A pulse every ~1.05 seconds is slightly less. :-) –  Eric Apr 27 '12 at 18:34

Your Answer

 
discard

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.