我的粒子重复

时间:2014-05-26 13:57:52

标签: c# visual-studio particles particle-engine

我失去了如何去除我的粒子的重复..每次我的角色用粒子射击第二个火球。它会重复自己

命名空间Particle_Effect {     class ParticleEngine     {         私人随机随机;         public Vector2 EmitterLocation {get;组; }         私人列表粒子;         私人列表纹理;

    public ParticleEngine(List<Texture2D> textures, Vector2 location)
    {
        EmitterLocation = location;
        this.textures = textures;
        this.particles = new List<Particle>();
        random = new Random();
    }

    private Particle GenerateNewParticle()
    {
        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(0);

        return new Particle(texture, position, velocity, angle, angularVelocity, color, size, ttl);
    }
    public void Update()
    {
        int total = 10;

        for (int i = 0; i < total; i++)
        {
            particles.Add(GenerateNewParticle());
        }

        for (int particle = 0; particle < particles.Count; particle++)
        {
            particles[particle].Update();
            if (particles[particle].TTL <= 0)
            {
                particles.RemoveAt(particle);
                particle--;
            }
        }
    }

    public void Draw(SpriteBatch spriteBatch)
    {
        //spriteBatch.Begin();
        for (int index = 0; index < particles.Count; index++)
        {
            particles[index].Draw(spriteBatch);
        }



        //spriteBatch.End();
    }
}

}

http://i907.photobucket.com/albums/ac271/Yankee_Lee/Untitled_zps0f99da0f.png

0 个答案:

没有答案
相关问题