Possible Duplicate:
Random number generator not working the way I had planned (C#)
Night, guys. Once again I'm having some trouble with mah code, yep.
This is the case, I got a list of objects of the class Star (white dots). I've overriden the Draw method so through a random value (from a static function) it should pick some stars and make 'em black for a short period of time, just to give that flickering effect.
The problem is, that all the stars go black at the same time, as they come back to normal... at the same time! Here is my code:
Stars = new List<Star>();
for (int x = 0; x < 90; x++)
Stars.Add(new Star(rnum(1024, rnumber), rnum(768, rnumber), pixel, 0.25f, 1));
for (int x = 0; x < 40; x++)
Stars.Add(new Star(rnum(1024, rnumber), rnum(768, rnumber), pixel, 1f, 2f));
for (int x = 0; x < 10; x++)
Stars.Add(new Star(rnum(1024, rnumber), rnum(768, rnumber), pixel, 1.5f, 3));
That's declaring. Parameters in order are X, Y, texture, speed and size.
for (int x = 0; x < Stars.Count; x++)
Stars[x].Draw(spriteBatch);
That's for drawing (I've also tried foreach)
if (blackCounter > 0)
{
spBatch.Draw(texture, position, new Rectangle(framePosition * (int)frameSize.X, 0, (int)frameSize.X, (int)frameSize.Y), Color.Black);
blackCounter--;
}
else
{
if (rNumber(20,rn) == 5)
blackCounter += rNumber(100,rn);
base.Draw(spBatch);
}
This is the overriden Draw method for the stars. blackCounter should go to a value from 0 to 100 in 1 of 20 cases, and then slowly go down, while painting the star black.
Here's a screenshot, sigh...
a busy cat http://img444.imageshack.us/img444/2930/clipboard01zy.png