コード例 #1
0
        public void UpdateParticle(Particle particle, long delta)
        {
            particleCount++;

            particle.x += adjustx;
            particle.y += adjusty;

            particle.AdjustVelocity(windFactor.GetValue(0) * 0.00005f * delta,
                                    gravityFactor.GetValue(0) * 0.00005f * delta);

            float offset    = particle.GetLife() / particle.GetOriginalLife();
            float inv       = 1 - offset;
            float colOffset = 0;
            float colInv    = 1;

            LColor startColor = null;
            LColor endColor   = null;

            for (int i = 0; i < colors.Count - 1; i++)
            {
                ColorRecord rec1 = (ColorRecord)colors[i];
                ColorRecord rec2 = (ColorRecord)colors[i + 1];

                if ((inv >= rec1.pos) && (inv <= rec2.pos))
                {
                    startColor = rec1.col;
                    endColor   = rec2.col;

                    float step = rec2.pos - rec1.pos;
                    colOffset  = inv - rec1.pos;
                    colOffset /= step;
                    colOffset  = 1 - colOffset;
                    colInv     = 1 - colOffset;
                }
            }

            if (startColor != null)
            {
                float r = (startColor.r * colOffset) + (endColor.r * colInv);
                float g = (startColor.g * colOffset) + (endColor.g * colInv);
                float b = (startColor.b * colOffset) + (endColor.b * colInv);

                float a;
                if (alpha.IsActive())
                {
                    a = alpha.GetValue(inv) / 255.0f;
                }
                else
                {
                    a = ((startAlpha.GetValue(0) / 255.0f) * offset)
                        + ((endAlpha.GetValue(0) / 255.0f) * inv);
                }
                particle.SetColor(r, g, b, a);
            }

            if (size.IsActive())
            {
                float s = size.GetValue(inv);
                particle.SetSize(s);
            }
            else
            {
                particle.AdjustSize(delta * growthFactor.GetValue(0) * 0.001f);
            }

            if (velocity.IsActive())
            {
                particle.SetSpeed(velocity.GetValue(inv));
            }

            if (scaleY.IsActive())
            {
                particle.SetScaleY(scaleY.GetValue(inv));
            }
        }
コード例 #2
0
        public void UpdateParticle(Particle particle, long delta)
        {
            particleCount++;

            particle.x += adjustx;
            particle.y += adjusty;

            particle.AdjustVelocity(windFactor.GetValue(0) * 0.00005f * delta,
                gravityFactor.GetValue(0) * 0.00005f * delta);

            float offset = particle.GetLife() / particle.GetOriginalLife();
            float inv = 1 - offset;
            float colOffset = 0;
            float colInv = 1;

            LColor startColor = null;
            LColor endColor = null;
            for (int i = 0; i < colors.Count - 1; i++) {
            ColorRecord rec1 = (ColorRecord) colors[i];
            ColorRecord rec2 = (ColorRecord) colors[i + 1];

            if ((inv >= rec1.pos) && (inv <= rec2.pos)) {
                startColor = rec1.col;
                endColor = rec2.col;

                float step = rec2.pos - rec1.pos;
                colOffset = inv - rec1.pos;
                colOffset /= step;
                colOffset = 1 - colOffset;
                colInv = 1 - colOffset;
            }
            }

            if (startColor != null) {
            float r = (startColor.r * colOffset) + (endColor.r * colInv);
            float g = (startColor.g * colOffset) + (endColor.g * colInv);
            float b = (startColor.b * colOffset) + (endColor.b * colInv);

            float a;
            if (alpha.IsActive()) {
                a = alpha.GetValue(inv) / 255.0f;
            } else {
                a = ((startAlpha.GetValue(0) / 255.0f) * offset)
                        + ((endAlpha.GetValue(0) / 255.0f) * inv);
            }
            particle.SetColor(r, g, b, a);
            }

            if (size.IsActive()) {
            float s = size.GetValue(inv);
            particle.SetSize(s);
            } else {
            particle.AdjustSize(delta * growthFactor.GetValue(0) * 0.001f);
            }

            if (velocity.IsActive()) {
            particle.SetSpeed(velocity.GetValue(inv));
            }

            if (scaleY.IsActive()) {
            particle.SetScaleY(scaleY.GetValue(inv));
            }
        }