TuneBlaster_.Particle.Initialize C# (CSharp) Method

Initialize() public method

public Initialize ( Vector2 position, Vector2 velocity, Vector2 acceleration, float lifetime, float scale, float rotationSpeed ) : void
position Vector2
velocity Vector2
acceleration Vector2
lifetime float
scale float
rotationSpeed float
return void
        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 = Engine.RandomBetween(0, MathHelper.TwoPi);
        }

Usage Example

Exemplo n.º 1
0
        /// <param name="p">the particle to initialize</param>
        /// <param name="where">the position on the screen that the particle should be
        /// </param>
        protected virtual void InitializeParticle(Particle p, Vector2 where)
        {
            // first, call PickRandomDirection to figure out which way the particle
            // will be moving. velocity and acceleration's values will come from this.
            Vector2 direction = PickRandomDirection();

            // pick some random values for our particle
            float velocity =
                Engine.RandomBetween(minInitialSpeed, maxInitialSpeed);
            float acceleration =
                Engine.RandomBetween(minAcceleration, maxAcceleration);
            float lifetime =
                Engine.RandomBetween(minLifetime, maxLifetime);
            float scale =
                Engine.RandomBetween(minScale, maxScale);
            float rotationSpeed =
                Engine.RandomBetween(minRotationSpeed, maxRotationSpeed);

            // then initialize it with those random values. initialize will save those,
            // and make sure it is marked as active.
            p.Initialize(
                where, velocity * direction, acceleration * direction,
                lifetime, scale, rotationSpeed);
        }