public void UpdateEmmitersTexture(String jsonPath, GraphicsDevice graphicsDevice, ContentManager content)
        {
            foreach (var item in Emitters)
            {
                item.Value.Parameters.Quantity = 1;

                if (item.Value.TexturePath.Equals(""))
                {
                    item.Value.Texture = new Texture2D(graphicsDevice, 1, 1);
                    // item.Value.Texture.SetData<Color>(new[] { Color.White });
                }
                else
                {
                    if (jsonPath.Equals(""))
                    {
                        item.Value.Texture = LoadImage(item.Value.TexturePath, graphicsDevice, content);
                    }
                    else
                    {
                        item.Value.Texture = LoadImage(jsonPath + item.Value.TexturePath, graphicsDevice, content);
                    }
                }

                if (item.Value.ModifierExecutionStrategy.Name.Equals("Parallel"))
                {
                    item.Value.ModifierExecutionStrategy = ModifierExecutionStrategy.Parallel();
                }
                else
                {
                    item.Value.ModifierExecutionStrategy = ModifierExecutionStrategy.Serial();
                }
            }
        }
Example #2
0
        public Emitter(int capacity, TimeSpan term, Profile profile)
        {
            if (profile == null)
            {
                throw new ArgumentNullException(nameof(profile));
            }

            _term = (float)term.TotalSeconds;

            Buffer = new ParticleBuffer(capacity);
            Offset = new Vector();

            switch (profile.Name)
            {
            case nameof(Profile.EnumEmitterProfiles.BoxFillProfile):
                Profile = Profile.BoxFill(profile.Width, profile.Height);
                break;

            case nameof(Profile.EnumEmitterProfiles.BoxProfile):
                Profile = Profile.Box(profile.Width, profile.Height);
                break;

            case nameof(Profile.EnumEmitterProfiles.BoxUniformProfile):
                Profile = Profile.BoxUniform(profile.Width, profile.Height);
                break;

            case nameof(Profile.EnumEmitterProfiles.CircleProfile):
                Profile = Profile.Circle(profile.Radius, profile.Radiate);
                break;

            case nameof(Profile.EnumEmitterProfiles.LineProfile):
                Profile = Profile.Line(profile.Axis, profile.Length);
                break;

            case nameof(Profile.EnumEmitterProfiles.PointProfile):
                Profile = Profile.Point();
                break;

            case nameof(Profile.EnumEmitterProfiles.RingProfile):
                Profile = Profile.Ring(profile.Radius, profile.Radiate);
                break;

            case nameof(Profile.EnumEmitterProfiles.SprayProfile):
                Profile = Profile.Spray(profile.Direction, profile.Spread);
                break;
            }

            if (Profile == null)
            {
                Profile = profile;
            }

            Modifiers = new Dictionary <string, IModifier>();
            ModifierExecutionStrategy = ModifierExecutionStrategy.Serial();

            Parameters = new ReleaseParameters();
        }
Example #3
0
        public void Update(float elapsedSeconds)
        {
            _totalSeconds            += elapsedSeconds;
            _secondsSinceLastReclaim += elapsedSeconds;

            if (Buffer.Count == 0)
            {
                return;
            }

            if (_secondsSinceLastReclaim > (1f / ReclaimFrequency))
            {
                ReclaimExpiredParticles();
                _secondsSinceLastReclaim -= (1f / ReclaimFrequency);
            }

            ReclaimExpiredParticles();

            var iterator = Buffer.Iterator;

            while (iterator.HasNext)
            {
                var particle = iterator.Next();
                particle->Age = (_totalSeconds - particle->Inception) / _term;

                if (particle->StartAge == 0)
                {
                    particle->StartAge = particle->Age;
                    particle->Term     = _term;
                }


                particle->Position = particle->Position + particle->Velocity * elapsedSeconds;
            }

            ModifierExecutionStrategy.ExecuteModifiers(Modifiers, elapsedSeconds, iterator);
        }