public void Update(ParticleSystem system, long delta) { timer -= delta; if (timer <= 0) { timer = interval; Particle p = system.GetNewParticle(this, 1000); p.SetColor(1, 1, 1, 0.5f); p.SetPosition(x, y); p.SetSize(size); float vx = (-0.02f + (MathUtils.Random() * 0.04f)); float vy = (-(MathUtils.Random() * 0.15f)); p.SetVelocity(vx, vy, 1.1f); } }
public void UpdateParticle(Particle particle, long delta) { particleCount++; particle.x += adjustx; particle.y += adjusty; particle.AdjustVelocity(windFactor.GetValue(0) * 0.00005f * delta, gravityFactor.GetValue(0) * 0.00005f * delta); float offset = particle.GetLife() / particle.GetOriginalLife(); float inv = 1 - offset; float colOffset = 0; float colInv = 1; LColor startColor = null; LColor endColor = null; for (int i = 0; i < colors.Count - 1; i++) { ColorRecord rec1 = (ColorRecord)colors[i]; ColorRecord rec2 = (ColorRecord)colors[i + 1]; if ((inv >= rec1.pos) && (inv <= rec2.pos)) { startColor = rec1.col; endColor = rec2.col; float step = rec2.pos - rec1.pos; colOffset = inv - rec1.pos; colOffset /= step; colOffset = 1 - colOffset; colInv = 1 - colOffset; } } if (startColor != null) { float r = (startColor.r * colOffset) + (endColor.r * colInv); float g = (startColor.g * colOffset) + (endColor.g * colInv); float b = (startColor.b * colOffset) + (endColor.b * colInv); float a; if (alpha.IsActive()) { a = alpha.GetValue(inv) / 255.0f; } else { a = ((startAlpha.GetValue(0) / 255.0f) * offset) + ((endAlpha.GetValue(0) / 255.0f) * inv); } particle.SetColor(r, g, b, a); } if (size.IsActive()) { float s = size.GetValue(inv); particle.SetSize(s); } else { particle.AdjustSize(delta * growthFactor.GetValue(0) * 0.001f); } if (velocity.IsActive()) { particle.SetSpeed(velocity.GetValue(inv)); } if (scaleY.IsActive()) { particle.SetScaleY(scaleY.GetValue(inv)); } }
public void Update(ParticleSystem system, long delta) { this.engine = system; if (!adjust) { adjustx = 0; adjusty = 0; } else { adjust = false; } if (updateImage) { updateImage = false; string name = (relativePath + imageName).Trim(); if (name.Length > 0) { try { image = LTextures.LoadTexture(name); } catch (Exception e) { image = null; Log.Exception(e); } } } if ((wrapUp) || ((length.IsEnabled()) && (timeout < 0)) || ((emitCount.IsEnabled() && (leftToEmit <= 0)))) { if (particleCount == 0) { completed = true; } } particleCount = 0; if (wrapUp) { return; } if (length.IsEnabled()) { if (timeout < 0) { return; } timeout -= delta; } if (emitCount.IsEnabled()) { if (leftToEmit <= 0) { return; } } nextSpawn -= delta; if (nextSpawn < 0) { nextSpawn = (int)spawnInterval.Random(); int count = (int)spawnCount.Random(); for (int i = 0; i < count; i++) { Particle p = system.GetNewParticle(this, initialLife.Random()); p.SetSize(initialSize.Random()); p.SetPosition(x + xOffset.Random(), y + yOffset.Random()); p.SetVelocity(0, 0, 0); float dist = initialDistance.Random(); float power = speed.Random(); if ((dist != 0) || (power != 0)) { float s = spread.GetValue(0); float ang = (s + angularOffset.GetValue(0) - (spread .GetValue() / 2)) - 90; float xa = MathUtils.Cos(MathUtils.ToRadians(ang)) * dist; float ya = MathUtils.Sin(MathUtils.ToRadians(ang)) * dist; p.AdjustPosition(xa, ya); float xv = MathUtils.Cos(MathUtils.ToRadians(ang)); float yv = MathUtils.Sin(MathUtils.ToRadians(ang)); p.SetVelocity(xv, yv, power * 0.001f); } if (image != null) { p.SetImage(image); } ColorRecord start = (ColorRecord)colors[0]; p.SetColor(start.col.r, start.col.g, start.col.b, startAlpha.GetValue(0) / 255.0f); p.SetUsePoint(usePoints); p.SetOriented(useOriented); if (emitCount.IsEnabled()) { leftToEmit--; if (leftToEmit <= 0) { break; } } } } }
public void UpdateParticle(Particle particle, long delta) { particleCount++; particle.x += adjustx; particle.y += adjusty; particle.AdjustVelocity(windFactor.GetValue(0) * 0.00005f * delta, gravityFactor.GetValue(0) * 0.00005f * delta); float offset = particle.GetLife() / particle.GetOriginalLife(); float inv = 1 - offset; float colOffset = 0; float colInv = 1; LColor startColor = null; LColor endColor = null; for (int i = 0; i < colors.Count - 1; i++) { ColorRecord rec1 = (ColorRecord) colors[i]; ColorRecord rec2 = (ColorRecord) colors[i + 1]; if ((inv >= rec1.pos) && (inv <= rec2.pos)) { startColor = rec1.col; endColor = rec2.col; float step = rec2.pos - rec1.pos; colOffset = inv - rec1.pos; colOffset /= step; colOffset = 1 - colOffset; colInv = 1 - colOffset; } } if (startColor != null) { float r = (startColor.r * colOffset) + (endColor.r * colInv); float g = (startColor.g * colOffset) + (endColor.g * colInv); float b = (startColor.b * colOffset) + (endColor.b * colInv); float a; if (alpha.IsActive()) { a = alpha.GetValue(inv) / 255.0f; } else { a = ((startAlpha.GetValue(0) / 255.0f) * offset) + ((endAlpha.GetValue(0) / 255.0f) * inv); } particle.SetColor(r, g, b, a); } if (size.IsActive()) { float s = size.GetValue(inv); particle.SetSize(s); } else { particle.AdjustSize(delta * growthFactor.GetValue(0) * 0.001f); } if (velocity.IsActive()) { particle.SetSpeed(velocity.GetValue(inv)); } if (scaleY.IsActive()) { particle.SetScaleY(scaleY.GetValue(inv)); } }