Time for action – updating and drawing particles
Add an
Update()
method to theParticle
class:Public Overrides Sub Update(gameTime As GameTime) If IsActive Then velocity += _acceleration If velocity.Length() > _maxSpeed velocity.Normalize() velocity *= _maxSpeed End If TintColor = Color.Lerp( _initialColor, _finalColor, DurationProgress) remainingDuration -= 1 MyBase.Update(gameTime) End If End Sub
Add a
Draw()
method to theParticle
class:Public Overrides Sub Draw(spriteBatch As SpriteBatch) If IsActive Then MyBase.Draw(spriteBatch) End If End Sub
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 behavior 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...