2
\$\begingroup\$

I followed rbwhitakers tutorial on making a particle engine and I'm wondering how to get more particles on the screen. I was thinking that the "total" variable would do it but it doesnt. Is this something I'm doing wrong in the method or a hardware problem?

private Particle GenerateNewParticle()
    {
        Texture2D texture = textures[random.Next(textures.Count)];
        Vector2 position = EmitterLocation;
        Vector2 velocity = new Vector2(0, 10);
        float angle = 0;
        float angularVelocity = 0;
        Color color = Color.LightSkyBlue;
        float size = (float)random.NextDouble();
        int ttl = 100;

        return new Particle(texture, position, velocity, angle, angularVelocity, color, size, ttl);
    }

    public void Update()
    {
        int total = 100;

        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[particle].Position.Y > 550)
            {
                particles.RemoveAt(particle);
                particle--;
            }
        }
    }

Im creating rain but I want it to be really heavy rain. Right now it just looks like a heavy sprinkle...I guess I would call it.

            particleEngine.EmitterLocation = new Vector2((float)rand.NextDouble() * (graphics.GraphicsDevice.Viewport.Width), 0);
\$\endgroup\$
2
\$\begingroup\$
    for (int i = 0; i < total; i++)
    {
        particles.Add(GenerateNewParticle());
    }

This is being called once per particleEngine.EmitterLocation assignment. This means you're creating 100 particles in the same location every frame.

Try this:

    for (int i = 0; i < total; i++)
    {
        particles.Add(GenerateNewParticle());
        EmitterLocation = new Vector2((float)rand.NextDouble() * (graphics.GraphicsDevice.Viewport.Width), 0);
    }

You may need to make graphics.GraphicsDevice.Viewport.Width available in this scope somehow.

\$\endgroup\$
  • \$\begingroup\$ @ChristianFrantz Neat. Don't forget to mark it as the answer, then. \$\endgroup\$ – Ben Oct 12 '14 at 4:11
  • 1
    \$\begingroup\$ I will as the timer thing ends. \$\endgroup\$ – Christian Frantz Oct 12 '14 at 4:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.