XNA对象列表的随机值不是随机的?

时间:2011-12-01 07:19:31

标签: c# random xna

  

可能重复:
  Random number generator not working the way I had planned (C#)

晚上,伙计们。我再次遇到麻烦的问题,是的。

就是这种情况,我得到了Star类(白点)的对象列表。我已经覆盖了Draw方法,所以通过一个随机值(来自一个静态函数)它应该选择一些星星并让它们在短时间内变黑,只是为了给出闪烁效果。

问题是,所有的星星同时变黑,因为它们恢复正常......同时!这是我的代码:

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));

那是在宣告。按顺序的参数是X,Y,纹理,速度和大小。

for (int x = 0; x < Stars.Count; x++)
     Stars[x].Draw(spriteBatch);

那是绘画(我也尝试过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);
 }

这是对星星的重写Draw方法。 blackCounter应该在20个案例中的1个中从0到100的值,然后慢慢地下降,同时将星形描绘为黑色。

这是一个截图,叹息 ...

a busy cat http://img444.imageshack.us/img444/2930/clipboard01zy.png

0 个答案:

没有答案
相关问题