예제 #1
0
        // initialize is called by ParticleSystem to set up the particle, and prepares
        // the particle for use.
        public void Initialize(Vector2 position, Vector2 velocity, Vector2 acceleration,
                               float lifetime, float scale, float rotationSpeed)
        {
            // set the values to the requested values
            this.Position      = position;
            this.Velocity      = velocity;
            this.Acceleration  = acceleration;
            this.Lifetime      = lifetime;
            this.Scale         = scale;
            this.RotationSpeed = rotationSpeed;

            // reset TimeSinceStart - we have to do this because particles will be
            // reused.
            this.TimeSinceStart = 0.0f;

            // set rotation to some random value between 0 and 360 degrees.
            this.Rotation = ParticleSystem.RandomBetween(0, MathHelper.TwoPi);
        }
예제 #2
0
        // this function is called when we want to demo the explosion effect. it
        // updates the timeTillExplosion timer, and starts another explosion effect
        // when the timer reaches zero.
        private void UpdateExplosions(float dt, Viewport viewport)
        {
            timeTillExplosion -= dt;
            if (timeTillExplosion < 0)
            {
                Vector2 where = Vector2.Zero;
                // create the explosion at some random point on the screen.
                where.X = ParticleSystem.RandomBetween(0, viewport.Width);
                where.Y = ParticleSystem.RandomBetween(0, viewport.Height);

                // the overall explosion effect is actually comprised of two particle
                // systems: the fiery bit, and the smoke behind it. add particles to
                // both of those systems.
                explosion.AddParticles(where);
                smoke.AddParticles(where);

                // reset the timer.
                timeTillExplosion = TimeBetweenExplosions;
            }
        }