@Override public void draw(SpriteBatch spriteBatch) { delta = Math.min(0.06f, Gdx.graphics.getDeltaTime()); this.setOrigin(0, 0); for (int i = particles.size - 1; i >= 0; i--) { Particle particle = particles.get(i); if (particle.life > 0) { updateParticle(particle); float dx = this.getWidth() / 2 * particle.scale; float dy = this.getHeight() / 2 * particle.scale; this.setColor(1, 1, 1, Math.max(particle.life / this.life, 0)); this.setScale(particle.scale); this.setPosition(particle.position.x - dx, particle.position.y - dy); if (!(particle.position.y - dy >= -10 && particle.position.y - dy <= 10) && !(particle.position.x - dx >= -10 && particle.position.x - dx <= 10)) { super.draw(spriteBatch); } else { particle.life = 0; } } else { particles.removeIndex(i); freeParticles.free(particle); } } }
private void updateParticle(Particle particle) { delta = Math.min(0.06f, Gdx.graphics.getDeltaTime()); if (particle.life > 0) { particle.life -= delta; particle.position.add(particle.velocity.x * delta * 10, particle.velocity.y * delta * 10); particle.velocity.mul((float) Math.pow(damping, delta)); particle.scale += this.delta_scale * delta / 5f; } }
public void update(int anim, int time) { float dt = (float) viewer.getDelta() * 0.001F; float grav = AnimatedFloat.getValue(gravity, anim, time); float deaccel = AnimatedFloat.getValue(gravity2, anim, time); if (emitterType == 1 || emitterType == 2) { float rate = AnimatedFloat.getValue(emissionRate, anim, time); float life = AnimatedFloat.getValue(lifespan, anim, time); float toSpawn = 0.0F; if (life != 0.0F) toSpawn = (dt * rate) / life + spawnRemainder; else toSpawn = spawnRemainder; if (toSpawn < 1.0F) { spawnRemainder = toSpawn; if (spawnRemainder < 0.0F) spawnRemainder = 0.0F; } else { int spawnCount = (int) toSpawn; if (spawnCount + particles.size() > 1000) spawnCount = 1000 - particles.size(); spawnRemainder = toSpawn - (float) spawnCount; float w = AnimatedFloat.getValue(areaWidth, anim, time) * 0.5F; float l = AnimatedFloat.getValue(areaLength, anim, time) * 0.5F; float speed = AnimatedFloat.getValue(emissionSpeed, anim, time); float var = AnimatedFloat.getValue(speedVariation, anim, time); float spread = AnimatedFloat.getValue(verticalRange, anim, time); float spread2 = AnimatedFloat.getValue(horizontalRange, anim, time); boolean en = true; int thisAnim = anim; if (thisAnim >= enabled.length) thisAnim = 0; if (enabled.length > 0 && enabled[thisAnim].used) en = enabled[thisAnim].getValue(time) != 0; if (en) { for (int i = 0; i < spawnCount; i++) { Particle p; if (emitterType == 1) p = PlaneEmitter.newParticle(this, anim, time, w, l, speed, var, spread, spread2); else p = SphereEmitter.newParticle(this, anim, time, w, l, speed, var, spread, spread2); particles.add(p); } } } } float speed = 1.0F; Vec3 t1 = new Vec3(); Vec3 t2 = new Vec3(); Vec3 t3 = new Vec3(); Point4f d = new Point4f(); Point4f c[] = new Point4f[3]; for (int i = 0; i < 3; i++) c[i] = new Point4f(); for (int i = 0; i < particles.size(); ) { Particle p = (Particle) particles.get(i); p.speed.add( Vec3.sub(Vec3.scale(p.down, grav * dt, t1), Vec3.scale(p.dir, deaccel * dt, t2), t3)); if (slowdown > 0.0F) speed = (float) Math.exp(-1F * slowdown * p.life); p.pos.add(Vec3.scale(p.speed, speed * dt, t1)); p.life += dt; float lifePos = p.life / p.maxLife; float s1 = size.data[0].x; float s2 = 0.0F; float s3 = 0.0F; if (size.data.length > 1) s2 = size.data[1].x; else s2 = s1; if (size.data.length > 2) s3 = size.data[2].x; else s3 = s2; p.size = lifeInterp(lifePos, 0.5F, s1 * scale.x, s2 * scale.y, s3 * scale.z); int limit = Math.min(3, color.data.length); for (int j = 0; j < limit; j++) { Point3f t = color.data[j]; c[j].set(t.x / 255F, t.y / 255F, t.z / 255F, (float) transparency.data[j] / 32767F); } if (limit < 3) { Point3f t = color.data[limit - 1]; for (int j = limit - 1; j < 3; j++) c[j].set(t.x / 255F, t.y / 255F, t.z / 255F, (float) transparency.data[j] / 32767F); } lifeInterp(lifePos, 0.5F, c[0], c[1], c[2], d); p.color.set(d); if (lifePos >= 1.0F) particles.remove(i); else i++; } }