0

I have a particle engine which creates an emitter at my mouse position.

particleEngine.EmitterLocation = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);

It's in the Update method in Game1.cs.

I have another class which is called Ball.cs with its bouncing physics, and Texture2D texture; Vector2 position.

Now how do I make the emitter / particles follow the ball instead?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Uffe Puffe
  • 105
  • 1
  • 12

1 Answers1

0

pass a reference to the particleEngine to the Ball class and set the EmitterLocation to the ball's location.

Example:

Game1, Initialize (for instance):

ParticleEngine particleEngine = new ParticleEngine();
Ball ball = new Ball(particleEngine);

In the Ball class:

class Ball
{
    ParticleEngine particleEngine;
    Vector2 position;

    public Ball(ParticleEngine particleEngine)
    {
        this.particleEngine = particleEngine;
    }

    public void Update(GameTime gameTime)
    {
        //Update position
        particleEngine.EmitterLocation = new Vector2(this.position.X, this.position.Y);
    }
}

I don't know how your particle engine works or anything about your code structure, but with the information given I did my best to implement an understandable example.

Sane
  • 594
  • 1
  • 6
  • 16
  • Was this helpul? If not, please provide more information, including your Ball class so that I can help you. – Sane Jul 26 '13 at 14:09