Time for action – updating and drawing particles
Add an
Update()
method to the Particle class:public override void Update(GameTime gameTime) { if (IsActive) { velocity += acceleration; if (velocity.Length() > maxSpeed) { velocity.Normalize(); velocity *= maxSpeed; } TintColor = Color.Lerp( initialColor, finalColor, DurationProgress); remainingDuration--; base.Update(gameTime); } }
Add a
Draw()
method to the Particle class:public override void Draw(SpriteBatch spriteBatch) { if (IsActive) { base.Draw(spriteBatch); } }
What just happened?
Both the Update()
and the Draw()
methods override the Sprite class' methods of the same name because we need to alter the behaviour associated with them. Both methods will only execute any code if the IsActive
property returns true. In fact, for the Draw()
method, this is the only reason we override the method...