Exemple #1
0
        public void LoadDescription(ParticleDesc desc)
        {
            this.Texture          = desc.Texture;
            this.ParticleCount    = desc.TotalParticle;
            this.Duration         = desc.Duration;
            this.OpacityModifyRGB = desc.OpacityModifyRGB;
            if (desc.Gravity != null)
            {
                this.Gravity = new Vector2(desc.Gravity.X, desc.Gravity.Y);
            }
            var alphaPointList = new List <AlphaPoint>();

            if (desc.MiddlePoint0 > 0)
            {
                alphaPointList.Add(new AlphaPoint(desc.MiddlePoint0 / 100f, desc.MiddlePointAlpha0));
            }
            if (desc.MiddlePoint1 > 0)
            {
                alphaPointList.Add(new AlphaPoint(desc.MiddlePoint1 / 100f, desc.MiddlePointAlpha1));
            }
            this.alphaPoints  = alphaPointList.ToArray();
            this.BlendFuncSrc = desc.BlendFuncSrc;
            this.BlendFuncDst = desc.BlendFuncDst;
            this.CreateEmitter(desc);
        }
Exemple #2
0
        private void CreateEmitter(ParticleDesc desc)
        {
            var emitter = new ParticleEmitter(this);

            emitter.Angle         = desc.Angle;
            emitter.AngleVar      = desc.AngleVar;
            emitter.StartColor    = desc.StartColor;
            emitter.StartColorVar = desc.StartColorVar;
            emitter.EndColor      = desc.EndColor;
            emitter.EndColorVar   = desc.EndColorVar;
            emitter.StartSize     = desc.StartSize;
            emitter.StartSizeVar  = desc.StartSizeVar;
            emitter.EndSize       = desc.EndSize;
            emitter.EndSizeVar    = desc.EndSizeVar;
            emitter.Pos           = new Vector2(desc.PosX, desc.PosY);
            emitter.PosVar        = new Vector2(desc.PosVarX, desc.PosVarY);
            emitter.StartSpin     = desc.StartSpin;
            emitter.StartSpinVar  = desc.StartSpinVar;
            emitter.EndSpin       = desc.EndSpin;
            emitter.EndSpinVar    = desc.EndSpinVar;
            if (desc.Gravity != null)
            {
                emitter.Speed              = desc.Gravity.Speed;
                emitter.SpeedVar           = desc.Gravity.SpeedVar;
                emitter.RadialAccel        = desc.Gravity.RadialAccel;
                emitter.RadialAccelVar     = desc.Gravity.RadialAccelVar;
                emitter.TangentialAccel    = desc.Gravity.TangentialAccel;
                emitter.TangentialAccelVar = desc.Gravity.TangentialAccelVar;
                emitter.RotationIsDir      = desc.Gravity.RotationIsDir;
            }
            if (desc.Radius != null)
            {
            }
            emitter.Life    = desc.Life;
            emitter.LifeVar = desc.LifeVar;

            //计算发射速率
            if (desc.Duration > 0)
            {
                emitter.EmissionRate = desc.TotalParticle / Math.Min(desc.Duration, 1);
            }
            else
            {
                float lifeMin = Math.Max(0, desc.Life - desc.LifeVar);
                float lifeMax = Math.Max(0, desc.Life + desc.LifeVar);
                var   life    = (lifeMin + lifeMax) / 2;
                if (life <= 0)
                {
                    life = 1;
                }
                emitter.EmissionRate = desc.TotalParticle / life;
            }

            this.Emitter = emitter;
        }
        public ParticleDesc LoadParticleDesc(Wz_Node node)
        {
            var desc = new ParticleDesc();

            desc.Name = node.Text;
            foreach (var pNode in node.Nodes)
            {
                switch (pNode.Text)
                {
                case "totalParticle": desc.TotalParticle = pNode.GetValue <int>(); break;

                case "angle": desc.Angle = pNode.GetValue <float>(); break;

                case "angleVar": desc.AngleVar = pNode.GetValue <float>(); break;

                case "duration": desc.Duration = pNode.GetValue <float>(); break;

                case "blendFuncSrc": desc.BlendFuncSrc = (ParticleBlendFunc)pNode.GetValue <int>(); break;

                case "blendFuncDst": desc.BlendFuncDst = (ParticleBlendFunc)pNode.GetValue <int>(); break;

                case "startColor": desc.StartColor = System.Drawing.Color.FromArgb(pNode.GetValue <int>()).ToXnaColor(); break;

                case "startColorVar": desc.StartColorVar = System.Drawing.Color.FromArgb(pNode.GetValue <int>()).ToXnaColor(); break;

                case "endColor": desc.EndColor = System.Drawing.Color.FromArgb(pNode.GetValue <int>()).ToXnaColor(); break;

                case "endColorVar": desc.EndColorVar = System.Drawing.Color.FromArgb(pNode.GetValue <int>()).ToXnaColor(); break;

                case "MiddlePoint0": desc.MiddlePoint0 = pNode.GetValue <int>(); break;

                case "MiddlePointAlpha0": desc.MiddlePointAlpha0 = pNode.GetValue <int>(); break;

                case "MiddlePoint1": desc.MiddlePoint1 = pNode.GetValue <int>(); break;

                case "MiddlePointAlpha1": desc.MiddlePointAlpha1 = pNode.GetValue <int>(); break;

                case "startSize": desc.StartSize = pNode.GetValue <float>(); break;

                case "startSizeVar": desc.StartSizeVar = pNode.GetValue <float>(); break;

                case "endSize": desc.EndSize = pNode.GetValue <float>(); break;

                case "endSizeVar": desc.EndSizeVar = pNode.GetValue <float>(); break;

                case "posX": desc.PosX = pNode.GetValue <float>(); break;

                case "posY": desc.PosY = pNode.GetValue <float>(); break;

                case "posVarX": desc.PosVarX = pNode.GetValue <float>(); break;

                case "posVarY": desc.PosVarY = pNode.GetValue <float>(); break;

                case "startSpin": desc.StartSpin = pNode.GetValue <float>(); break;

                case "startSpinVar": desc.StartSpinVar = pNode.GetValue <float>(); break;

                case "endSpin": desc.EndSpin = pNode.GetValue <float>(); break;

                case "endSpinVar": desc.EndSpinVar = pNode.GetValue <float>(); break;

                case "GRAVITY":
                {
                    var gravityDesc = new ParticleGravityDesc();
                    foreach (var pNode2 in pNode.Nodes)
                    {
                        switch (pNode2.Text)
                        {
                        case "x": gravityDesc.X = pNode2.GetValue <float>(); break;

                        case "y": gravityDesc.Y = pNode2.GetValue <float>(); break;

                        case "speed": gravityDesc.Speed = pNode2.GetValue <float>(); break;

                        case "speedVar": gravityDesc.SpeedVar = pNode2.GetValue <float>(); break;

                        case "radialAccel": gravityDesc.RadialAccel = pNode2.GetValue <float>(); break;

                        case "radialAccelVar": gravityDesc.RadialAccelVar = pNode2.GetValue <float>(); break;

                        case "tangentialAccel": gravityDesc.TangentialAccel = pNode2.GetValue <float>(); break;

                        case "tangentialAccelVar": gravityDesc.TangentialAccelVar = pNode2.GetValue <float>(); break;

                        case "rotationIsDir": gravityDesc.RotationIsDir = pNode2.GetValue <int>() != 0; break;
                        }
                    }
                    desc.Gravity = gravityDesc;
                }
                break;

                case "RADIUS":
                {
                    var radiusDesc = new ParticleRadiusDesc();
                    foreach (var pNode2 in pNode.Nodes)
                    {
                        switch (pNode2.Text)
                        {
                        case "startRadius": radiusDesc.StartRadius = pNode2.GetValue <float>(); break;

                        case "startRadiusVar": radiusDesc.StartRadiusVar = pNode2.GetValue <float>(); break;

                        case "endRadius": radiusDesc.EndRadius = pNode2.GetValue <float>(); break;

                        case "endRadiusVar": radiusDesc.EndRadiusVar = pNode2.GetValue <float>(); break;

                        case "rotatePerSecond": radiusDesc.RotatePerSecond = pNode2.GetValue <float>(); break;

                        case "rotatePerSecondVar": radiusDesc.RotatePerSecondVar = pNode2.GetValue <float>(); break;
                        }
                    }
                    desc.Radius = radiusDesc;
                }
                break;

                case "life": desc.Life = pNode.GetValue <float>(); break;

                case "lifeVar": desc.LifeVar = pNode.GetValue <float>(); break;

                case "opacityModifyRGB": desc.OpacityModifyRGB = pNode.GetValue <int>() != 0; break;

                case "positionType": desc.PositionType = pNode.GetValue <int>(); break;

                case "texture":
                    desc.Texture = this.LoadFrame(pNode);
                    break;
                }
            }
            return(desc);
        }