예제 #1
0
        /// <summary>
        /// Create a new particle effect, based on parameters stored in ParticleEffectData.xml
        /// </summary>
        /// <param name="effectKey">string identifier used to fetch parameters. Must match Name attribute in XML</param>
        public ParticleEffect(string effectKey)
        {
            if (Data.ContainsKey(effectKey))
            {
                ParticleEffectData data = Data[effectKey];
                _generators = new ParticleGenerator[data.ParticleGenerators.Length];
                for (int i = 0; i < _generators.Length; i++)
                {
                    _generators[i] = new ParticleGenerator(data.ParticleGenerators[i]);
                }
            }
            else
            {
                _generators    = new ParticleGenerator[1];
                _generators[0] = new ParticleGenerator(effectKey);
            }

            IntensityFactor = 1.0f;
        }
        /// <summary>
        /// Create a new particle effect, based on parameters stored in ParticleEffectData.xml
        /// </summary>
        /// <param name="effectKey">string identifier used to fetch parameters. Must match Name attribute in XML</param>
        public ParticleEffect(string effectKey)
        {
            _particleEffectData = Data[effectKey];
            _particleSpeed = _particleEffectData.Speed;
            _speedVariance = _particleEffectData.SpeedVariance;
            _particleDecelerationFactor = _particleEffectData.DecelerationFactor;

            _particleTexture = (_particleEffectData.UniqueParticle == null) ? particleTexture : _particleEffectData.UniqueParticle;
            _textureCenter = new Vector2(_particleTexture.Width / 2.0f, particleTexture.Height / 2.0f);

            _particleScale = _particleEffectData.StartScale / _particleTexture.Width;
            _scaleRate =
                (((_particleEffectData.EndScale - _particleEffectData.StartScale) / _particleTexture.Width)
                / ((float)_particleEffectData.ParticleLife.TotalSeconds));
            _scaleVariance = _particleEffectData.ScaleVariance;
            _arc = _particleEffectData.SpawnArc;
            _particleLife = _particleEffectData.ParticleLife;
            _particleLifeVariance = _particleEffectData.ParticleLifeVariance;
            _particleRotationSpeed = MathHelper.ToRadians(
                _particleEffectData.ParticleRotation / (float)_particleEffectData.ParticleLife.TotalSeconds);
            if (_particleEffectData.Reversed)
            {
                _startColor = _particleEffectData.EndColor;
                _endColor = _particleEffectData.StartColor;
                Reversed = true;
            }
            else
            {
                _startColor = _particleEffectData.StartColor;
                _endColor = _particleEffectData.EndColor;
                Reversed = false;
            }

            _spawnRate = _particleEffectData.SpawnRate;
            _tillNextParticleSpawn = TimeSpan.FromSeconds(1.0f / (float)_spawnRate);
            _particles = new List<Particle>();
            IntensityFactor = 1.0f;
        }