public ParticleGenerator(ParticleGeneratorData data)
        {
            _particleEffectData = data;
            _particleSpeed = _particleEffectData.Speed;
            _speedVariance = _particleEffectData.SpeedVariance;
            _particleDecelerationFactor = _particleEffectData.DecelerationFactor;

            _particleTexture = (_particleEffectData.UniqueParticle == null) ?
                particleTexture : Content.Load<Texture2D>(PARTICLE_TEXTURE_DIRECTORY + _particleEffectData.UniqueParticle);
            _textureCenter = new Vector2(_particleTexture.Width / 2.0f, _particleTexture.Height / 2.0f);

            if (_particleEffectData.BaseTexture != null)
            {
                _baseTexture = Content.Load<Texture2D>(PARTICLE_TEXTURE_DIRECTORY + _particleEffectData.BaseTexture);
                _baseTextureCenter = new Vector2(_baseTexture.Width / 2.0f, _baseTexture.Height / 2.0f);
            }

            _particleScale = _particleEffectData.StartScale / _particleTexture.Width;

            _particleLife = TimeSpan.FromSeconds(_particleEffectData.ParticleLife);
            _particleLifeVariance = _particleEffectData.ParticleLifeVariance;

            _scaleRate =
                (((_particleEffectData.EndScale - _particleEffectData.StartScale) / _particleTexture.Width)
                / ((float)_particleLife.TotalSeconds));
            _scaleVariance = _particleEffectData.ScaleVariance;
            _arc = _particleEffectData.SpawnArc;
            _offset = _particleEffectData.Offset;
            _particleRotationSpeed = MathHelper.ToRadians(
                _particleEffectData.ParticleRotation / (float)_particleLife.TotalSeconds);

            byte[] scv = _particleEffectData.StartColor.Split(',')
                .Select(n => Convert.ToByte(n)).ToArray();
            byte[] ecv = _particleEffectData.EndColor.Split(',')
                .Select(n => Convert.ToByte(n)).ToArray();

            if (_particleEffectData.Reversed)
            {
                _startColor = new Color(ecv[1], ecv[2], ecv[3], ecv[0]);
                _endColor = new Color(scv[1], scv[2], scv[3], scv[0]);
                Reversed = true;
            }
            else
            {
                _startColor = new Color(scv[1], scv[2], scv[3], scv[0]);
                _endColor = new Color(ecv[1], ecv[2], ecv[3], ecv[0]);
                Reversed = false;
            }

            _spawnRate = _particleEffectData.SpawnRate;
            _tillNextParticleSpawn = TimeSpan.FromSeconds(1.0f / (float)_spawnRate);
            _particles = new List<Particle>();
            IntensityFactor = 1.0f;
        }
示例#2
0
        public ParticleGenerator(ParticleGeneratorData data)
        {
            _particleEffectData         = data;
            _particleSpeed              = _particleEffectData.Speed;
            _speedVariance              = _particleEffectData.SpeedVariance;
            _particleDecelerationFactor = _particleEffectData.DecelerationFactor;

            _particleTexture = (_particleEffectData.UniqueParticle == null) ?
                               particleTexture : Content.Load <Texture2D>(PARTICLE_TEXTURE_DIRECTORY + _particleEffectData.UniqueParticle);
            _textureCenter = new Vector2(_particleTexture.Width / 2.0f, particleTexture.Height / 2.0f);

            _particleScale = _particleEffectData.StartScale / _particleTexture.Width;

            _particleLife         = TimeSpan.FromSeconds(_particleEffectData.ParticleLife);
            _particleLifeVariance = _particleEffectData.ParticleLifeVariance;

            _scaleRate =
                (((_particleEffectData.EndScale - _particleEffectData.StartScale) / _particleTexture.Width)
                 / ((float)_particleLife.TotalSeconds));
            _scaleVariance         = _particleEffectData.ScaleVariance;
            _arc                   = _particleEffectData.SpawnArc;
            _offset                = _particleEffectData.Offset;
            _particleRotationSpeed = MathHelper.ToRadians(
                _particleEffectData.ParticleRotation / (float)_particleLife.TotalSeconds);

            byte[] scv = _particleEffectData.StartColor.Split(',')
                         .Select(n => Convert.ToByte(n)).ToArray();
            byte[] ecv = _particleEffectData.EndColor.Split(',')
                         .Select(n => Convert.ToByte(n)).ToArray();

            if (_particleEffectData.Reversed)
            {
                _startColor = new Color(ecv[1], ecv[2], ecv[3], ecv[0]);
                _endColor   = new Color(scv[1], scv[2], scv[3], scv[0]);
                Reversed    = true;
            }
            else
            {
                _startColor = new Color(scv[1], scv[2], scv[3], scv[0]);
                _endColor   = new Color(ecv[1], ecv[2], ecv[3], ecv[0]);
                Reversed    = false;
            }

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