1
当我创建粒子效果时,它们都具有相同的模式。他们旋转,但他们都有相同的模式和相同的彩色粒子。见图片:显示相同粒子的粒子效应 - 不随机化,Monogame
这是一个新的ParticleEffect创建方式:
ParticleEffect p = new ParticleEffect(textures, Vector2.Zero, destination, speed);
凡textures
是Texture2D
名单,VectorZero是起始位置,等等。
每当一个新的ParticleEffect
被创建它被添加到列表ParticleList
,后来通过所有的项目循环,并呼吁内部的每个效果update
和draw
。
下面是其中颗粒是随机的:
private Particle GenerateNewParticle()
{
Random random = new Random();
Texture2D texture = textures[random.Next(textures.Count)];
Vector2 position = EmitterLocation;
Vector2 velocity = new Vector2(
1f * (float)(random.NextDouble() * 2 - 1),
1f * (float)(random.NextDouble() * 2 - 1));
float angle = 0;
float angularVelocity = 0.1f * (float)(random.NextDouble() * 2 - 1);
Color color = new Color(
(float)random.NextDouble(),
(float)random.NextDouble(),
(float)random.NextDouble());
float size = (float)random.NextDouble();
int ttl = 20 + random.Next(40);
return new Particle(texture, position, velocity, angle, angularVelocity, color, size, ttl);
}
的randoms
有一束,但每个效果仍然出来的相同。 评论,如果你想看到更多的代码。
编辑: 这里是一个粒子被绘制方式:
public void Draw(SpriteBatch spriteBatch)
{
Rectangle sourceRectangle = new Rectangle(0, 0, Texture.Width, Texture.Height);
Vector2 origin = new Vector2(Texture.Width/2, Texture.Height/2);
spriteBatch.Draw(Texture, Position, sourceRectangle, Color,
Angle, origin, Size, SpriteEffects.None, 0f);
}