Пример #1
0
 protected void SpawnCircle(Particle p, float emitPosX, float emitPosY, float i = -1f)
 {
     //set the initial rotation/direction of the particle based on starting
     //particle angle and rotation of emitter
     if (minStartRotation == maxStartRotation)
     {
         p.Rotation = minStartRotation + rotation;
     }
     else
     {
         p.Rotation = Mathf.Random() * (maxStartRotation - minStartRotation) +
                      minStartRotation + rotation;
     }
     //place the particle at a random radius in the circle
     helperPoint.X = Mathf.Random() * spawnCircle.radius;
     helperPoint.Y = 0;
     //rotate the point to a random angle in the circle
     helperPoint = ParticleUtils.RotatePoint(Mathf.Random() * 360, helperPoint);
     //offset by the circle's center
     helperPoint.X += spawnCircle.x;
     helperPoint.Y += spawnCircle.y;
     //rotate the point by the emitter's rotation
     if (rotation != 0)
     {
         ParticleUtils.RotatePoint(rotation, helperPoint);
     }
     //set the position, offset by the emitter's position
     p.X = emitPosX + helperPoint.X;
     p.Y = emitPosY + helperPoint.Y;
 }
Пример #2
0
        /// <summary>
        /// Sets the rotation of the emitter to a new value.
        /// </summary>
        /// <param name="newRot">The new rotation, in degrees.</param>
        public void Rotate(float newRot)
        {
            if (rotation == newRot)
            {
                return;
            }
            //caclulate the difference in rotation for rotating spawnPos
            var diff = newRot - rotation;

            rotation = newRot;
            //rotate spawnPos
            spawnPos = ParticleUtils.RotatePoint(diff, spawnPos);
            //mark the position as having changed
            posChanged = true;
        }
Пример #3
0
        /// <summary>
        /// Initializes the particle for use, based on the properties that have to
        /// have been set already on the particle.
        /// </summary>
        public void Init()
        {
            //reset the age
            age = 0f;
            //set up the velocity based on the start speed and rotation
            velocity.X = speedList.current.value * speedMultiplier;
            velocity.Y = 0;
            velocity   = ParticleUtils.RotatePoint(Rotation, velocity);
            if (noRotation)
            {
                Rotation = 0;
            }
            else
            {
                //convert rotation to Radians from Degrees
                Rotation *= ParticleUtils.DEG_TO_RADS;
            }
            //convert rotation speed to Radians from Degrees
            rotationSpeed        *= ParticleUtils.DEG_TO_RADS;
            rotationAcceleration *= ParticleUtils.DEG_TO_RADS;

            //set alpha to inital alpha
            Alpha = alphaList.current.value;
            //set scale to initial scale
            Scale = new Vector2(scaleList.current.value, scaleList.current.value);
            //figure out what we need to interpolate
            doAlpha        = (alphaList.current.next != null);
            doSpeed        = (speedList.current.next != null);
            doScale        = (scaleList.current.next != null);
            doColor        = (colorList.current.next != null);
            doAcceleration = acceleration.X != 0 || acceleration.Y != 0;
            //_doNormalMovement can be cancelled by subclasses
            doNormalMovement = doSpeed || speedList.current.value != 0 || doAcceleration;
            //save our lerp helper
            oneOverLife = 1 / maxLife;
            //set the inital color
            var color = colorList.current.value;

            Tint = new Color(color.R, color.G, color.B);
            //ensure visibility
            Visible = true;
        }
Пример #4
0
 protected void SpawnRect(Particle p, float emitPosX, float emitPosY, float i = -1f)
 {
     //set the initial rotation/direction of the particle based on starting
     //particle angle and rotation of emitter
     if (minStartRotation == maxStartRotation)
     {
         p.Rotation = minStartRotation + rotation;
     }
     else
     {
         p.Rotation = Mathf.Random() * (maxStartRotation - minStartRotation) + minStartRotation + rotation;
     }
     //place the particle at a random point in the rectangle
     helperPoint.X = Mathf.Random() * spawnRect.Width + spawnRect.X;
     helperPoint.Y = Mathf.Random() * spawnRect.Height + spawnRect.Y;
     if (rotation != 0)
     {
         helperPoint = ParticleUtils.RotatePoint(rotation, helperPoint);
     }
     p.X = emitPosX + helperPoint.X;
     p.Y = emitPosY + helperPoint.Y;
 }