Пример #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++;
          }
        }
      }
    }
  }
Пример #2
0
 /** Returns the emitter with the specified name, or null. */
 public ParticleEmitter findEmitter(String name) {
   for (int i = 0, n = emitters.size; i < n; i++) {
     ParticleEmitter emitter = emitters.get(i);
     if (emitter.getName().equals(name)) return emitter;
   }
   return null;
 }
Пример #3
0
 public void setDuration(int duration) {
   for (int i = 0, n = emitters.size; i < n; i++) {
     ParticleEmitter emitter = emitters.get(i);
     emitter.setContinuous(false);
     emitter.duration = duration;
     emitter.durationTimer = 0;
   }
 }
Пример #4
0
 public boolean isComplete() {
   for (int i = 0, n = emitters.size; i < n; i++) {
     ParticleEmitter emitter = emitters.get(i);
     if (emitter.isContinuous()) return false;
     if (!emitter.isComplete()) return false;
   }
   return true;
 }
Пример #5
0
 public void loadEmitterImages(FileHandle imagesDir) {
   for (int i = 0, n = emitters.size; i < n; i++) {
     ParticleEmitter emitter = emitters.get(i);
     String imagePath = emitter.getImagePath();
     if (imagePath == null) continue;
     String imageName = new File(imagePath.replace('\\', '/')).getName();
     emitter.setSprite(new Sprite(loadTexture(imagesDir.child(imageName))));
   }
 }
Пример #6
0
  public void reset() {
    Iterator<ParticlePool> pools = particlesByEmitter.values().iterator();
    while (pools.hasNext()) {
      ParticlePool pool = pools.next();
      pool.reset(this);
    }

    for (int i = 0; i < emitters.size(); i++) {
      ParticleEmitter emitter = emitters.get(i);
      emitter.resetState();
    }
  }
Пример #7
0
 public void loadEmitterImages(TextureAtlas atlas) {
   for (int i = 0, n = emitters.size; i < n; i++) {
     ParticleEmitter emitter = emitters.get(i);
     String imagePath = emitter.getImagePath();
     if (imagePath == null) continue;
     String imageName = new File(imagePath.replace('\\', '/')).getName();
     int lastDotIndex = imageName.lastIndexOf('.');
     if (lastDotIndex != -1) imageName = imageName.substring(0, lastDotIndex);
     Sprite sprite = atlas.createSprite(imageName);
     if (sprite == null)
       throw new IllegalArgumentException("SpriteSheet missing image: " + imageName);
     emitter.setSprite(sprite);
   }
 }
Пример #8
0
 public void save(File file) {
   Writer output = null;
   try {
     output = new FileWriter(file);
     int index = 0;
     for (int i = 0, n = emitters.size; i < n; i++) {
       ParticleEmitter emitter = emitters.get(i);
       if (index++ > 0) output.write("\n\n");
       emitter.save(output);
       output.write("- Image Path -\n");
       output.write(emitter.getImagePath() + "\n");
     }
   } catch (IOException ex) {
     throw new GdxRuntimeException("Error saving effect: " + file, ex);
   } finally {
     try {
       if (output != null) output.close();
     } catch (IOException ex) {
     }
   }
 }
Пример #9
0
 public void loadEmitters(FileHandle effectFile) {
   InputStream input = effectFile.read();
   emitters.clear();
   BufferedReader reader = null;
   try {
     reader = new BufferedReader(new InputStreamReader(input), 512);
     while (true) {
       ParticleEmitter emitter = new ParticleEmitter(reader);
       reader.readLine();
       emitter.setImagePath(reader.readLine());
       emitters.add(emitter);
       if (reader.readLine() == null) break;
       if (reader.readLine() == null) break;
     }
   } catch (IOException ex) {
     throw new GdxRuntimeException("Error loading effect: " + effectFile, ex);
   } finally {
     try {
       if (reader != null) reader.close();
     } catch (IOException ex) {
     }
   }
 }
Пример #10
0
  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);
  }
Пример #11
0
  /**
   * Render the particles in the system
   *
   * @param x The x coordinate to render the particle system at (in the current coordinate space)
   * @param y The y coordinate to render the particle system at (in the current coordiante space)
   */
  public void render(float x, float y) {
    if ((sprite == null) && (defaultImageName != null)) {
      loadSystemParticleImage();
    }

    if (!visible) {
      return;
    }

    GL.glTranslatef(x, y, 0);

    if (blendingMode == BLEND_ADDITIVE) {
      GL.glBlendFunc(SGL.GL_SRC_ALPHA, SGL.GL_ONE);
    }
    if (usePoints()) {
      GL.glEnable(SGL.GL_POINT_SMOOTH);
      TextureImpl.bindNone();
    }

    // iterate over all emitters
    for (int emitterIdx = 0; emitterIdx < emitters.size(); emitterIdx++) {
      // get emitter
      ParticleEmitter emitter = (ParticleEmitter) emitters.get(emitterIdx);

      // check for additive override and enable when set
      if (emitter.useAdditive()) {
        GL.glBlendFunc(SGL.GL_SRC_ALPHA, SGL.GL_ONE);
      }

      // now get the particle pool for this emitter and render all particles that are in use
      ParticlePool pool = (ParticlePool) particlesByEmitter.get(emitter);
      Image image = emitter.getImage();
      if (image == null) {
        image = this.sprite;
      }

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

      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.endUse();
      }

      // reset additive blend mode
      if (emitter.useAdditive()) {
        GL.glBlendFunc(SGL.GL_SRC_ALPHA, SGL.GL_ONE_MINUS_SRC_ALPHA);
      }
    }

    if (usePoints()) {
      GL.glDisable(SGL.GL_POINT_SMOOTH);
    }
    if (blendingMode == BLEND_ADDITIVE) {
      GL.glBlendFunc(SGL.GL_SRC_ALPHA, SGL.GL_ONE_MINUS_SRC_ALPHA);
    }

    Color.white.bind();
    GL.glTranslatef(-x, -y, 0);
  }
Пример #12
0
 /** Disposes the texture for each sprite for each ParticleEmitter. */
 public void dispose() {
   for (int i = 0, n = emitters.size; i < n; i++) {
     ParticleEmitter emitter = emitters.get(i);
     emitter.getSprite().getTexture().dispose();
   }
 }
Пример #13
0
 public void draw(ParticleEmitter emitter, TextureAtlas.AtlasRegion tex, boolean additive) {
   maybeChangeAdditive(additive);
   emitter.draw(myDrawer.getBatch(emitter.getSprite().getTexture(), tex));
 }