예제 #1
0
        /// <summary>
        /// Initialize the rocket projectile to it's default gameplay states.
        /// </summary>
        public override void Initialize()
        {
            if (!active)
            {
                // get and play the rocket-flying sound effect

                AudioManager.PlaySoundEffect("rocket", true, out rocketSound);

                // start the rocket-trail effect
                if (ParticleEffectManager != null)
                {
                    rocketTrailEffect = ParticleEffectManager.SpawnEffect(
                        ParticleEffectType.RocketTrail, this);
                }
            }

            base.Initialize();
        }
 /// <summary>
 /// Register a new type of particle effect with the manager.
 /// </summary>
 /// <param name="effectType">The enumeration associated with this type.</param>
 /// <param name="filename">The path to the XML file to be deserialized.</param>
 /// <param name="initialCount">How many of these to pre-create.</param>
 public void RegisterParticleEffect(ParticleEffectType effectType,
                                    string filename, int initialCount)
 {
     if (!particleEffectCache.ContainsKey(effectType))
     {
         string         filepath       = Path.Combine(contentManager.RootDirectory, filename);
         ParticleEffect particleEffect = ParticleEffect.Load(filepath);
         particleEffect.Initialize(contentManager);
         particleEffect.Stop(true);
         particleEffectCache.Add(effectType, new List <ParticleEffect>());
         particleEffectCache[effectType].Add(particleEffect);
         for (int i = 1; i < initialCount; i++)
         {
             ParticleEffect cloneEffect = particleEffect.Clone();
             cloneEffect.Initialize(contentManager);
             cloneEffect.Stop(true);
             particleEffectCache[effectType].Add(cloneEffect);
         }
     }
 }
        /// <summary>
        /// Spawn a new particle effect at a given location and gameplay object
        /// </summary>
        /// <param name="effectType">The effect in question.</param>
        /// <param name="position">The position of the effect.</param>
        /// <param name="actor">The gameplay object.</param>
        /// <returns>The new particle effect.</returns>
        public ParticleEffect SpawnEffect(ParticleEffectType effectType,
                                          Vector2 position, GameplayObject gameplayObject)
        {
            ParticleEffect particleEffect = null;

            if (particleEffectCache.ContainsKey(effectType) == true)
            {
                List <ParticleEffect> availableSystems = particleEffectCache[effectType];

                for (int i = 0; i < availableSystems.Count; ++i)
                {
                    if (availableSystems[i].Active == false)
                    {
                        particleEffect = availableSystems[i];
                        break;
                    }
                }

                if (particleEffect == null)
                {
                    particleEffect = availableSystems[0].Clone();
                    particleEffect.Initialize(contentManager);
                    availableSystems.Add(particleEffect);
                }
            }

            if (particleEffect != null)
            {
                particleEffect.Reset();
                particleEffect.GameplayObject = gameplayObject;
                particleEffect.Position       = position;
                activeParticleEffects.Add(particleEffect);
            }

            return(particleEffect);
        }