Exemple #1
1
  /**
   * Update the system, request the assigned emitters update the particles
   *
   * @param delta The amount of time thats passed since last update in milliseconds
   */
  public void update(int delta) {
    if ((sprite == null) && (defaultImageName != null)) {
      loadSystemParticleImage();
    }

    ArrayList removeMe = new ArrayList();
    for (int i = 0; i < emitters.size(); i++) {
      ParticleEmitter emitter = (ParticleEmitter) emitters.get(i);
      if (emitter.isEnabled()) {
        emitter.update(this, delta);
        if (removeCompletedEmitters) {
          if (emitter.completed()) {
            removeMe.add(emitter);
            particlesByEmitter.remove(emitter);
          }
        }
      }
    }
    emitters.removeAll(removeMe);

    pCount = 0;

    if (!particlesByEmitter.isEmpty()) {
      Iterator it = particlesByEmitter.values().iterator();
      while (it.hasNext()) {
        ParticlePool pool = (ParticlePool) it.next();
        for (int i = 0; i < pool.particles.length; i++) {
          if (pool.particles[i].life > 0) {
            pool.particles[i].update(delta);
            pCount++;
          }
        }
      }
    }
  }
  public void render(GLEx g, float x, float y) {

    if (!visible) {
      return;
    }

    if ((sprite == null) && (defaultImageName != null)) {
      loadSystemParticleImage();
    }

    g.translate(x, y);

    if (blendingMode == BLEND_ADDITIVE) {
      GLEx.self.setBlendMode(GL.MODE_ALPHA_ONE);
    }
    if (usePoints()) {
      GLEx.gl10.glEnable(GL.GL_POINT_SMOOTH);
      g.glTex2DDisable();
    }

    for (int emitterIdx = 0; emitterIdx < emitters.size(); emitterIdx++) {

      ParticleEmitter emitter = emitters.get(emitterIdx);

      if (!emitter.isEnabled()) {
        continue;
      }

      if (emitter.useAdditive()) {
        g.setBlendMode(GL.MODE_ALPHA_ONE);
      }

      ParticlePool pool = particlesByEmitter.get(emitter);
      LTexture image = emitter.getImage();
      if (image == null) {
        image = this.sprite;
      }

      if (!emitter.isOriented() && !emitter.usePoints(this)) {
        image.glBegin();
      }

      for (int i = 0; i < pool.particles.length; i++) {
        if (pool.particles[i].inUse()) {
          pool.particles[i].render();
        }
      }

      if (!emitter.isOriented() && !emitter.usePoints(this)) {
        image.glEnd();
      }

      if (emitter.useAdditive()) {
        g.setBlendMode(GL.MODE_NORMAL);
      }
    }

    if (usePoints()) {
      GLEx.gl10.glDisable(GL.GL_POINT_SMOOTH);
    }
    if (blendingMode == BLEND_ADDITIVE) {
      g.setBlendMode(GL.MODE_NORMAL);
    }

    g.resetColor();
    g.translate(-x, -y);
  }