I’ve got this little bit where a selected unit gets bigger and smaller (kind of pulsing):
and this is the code that does it:
if (BlueArmy[i].IsPulsing)
{ // animating the unit under the cursor
KewlFX = KewlFX + Incrementer;
if (KewlFX > .9)
Incrementer = -0.01f;
if (KewlFX < (float)PieceSize)
Incrementer = 0.01f;
spriteBatch.Draw(ShadowImage,
new Vector2(BlueArmy[i].Location.X
+ 2 // drop shadow offset
+ LeftMapOffset,
BlueArmy[i].Location.Y
+ 2 // drop shadow offset
+ TopMapOffset)
, null // rect for source
, Color.White * 0.5f, // opacity is 50%
(float)BlueArmy[i].Facing // rotation
, origin // rotation center
, KewlFX + Incrementer // scale 50% we need to adjust this for different piece sizes
, SpriteEffects.None,
0f // layer depth
);
spriteBatch.Draw(UnitImage, new Vector2(
BlueArmy[i].Location.X
+ LeftMapOffset,
BlueArmy[i].Location.Y
+ TopMapOffset), null,
Color.White, // opacity is 100%
(float)BlueArmy[i].Facing, origin,
KewlFX + Incrementer, SpriteEffects.None, 0f);
}
But, here’s the weird part. If I have a LOT of units pulsing:
the units pulse faster! A LOT! faster!
I can’t be the first person to trip over this. Why is that the more units being drawn the faster the pulsing?