\r
import com.badlogic.gdx.files.FileHandle;\r
import com.badlogic.gdx.graphics.Texture;\r
+import com.badlogic.gdx.math.collision.BoundingBox;\r
import com.badlogic.gdx.utils.Array;\r
import com.badlogic.gdx.utils.Disposable;\r
import com.badlogic.gdx.utils.GdxRuntimeException;\r
+import com.badlogic.gdx.utils.StreamUtils;\r
\r
/** See <a href="http://www.badlogicgames.com/wordpress/?p=1255">http://www.badlogicgames.com/wordpress/?p=1255</a>\r
* @author mzechner */\r
public class ParticleEffect implements Disposable {\r
private final Array<ParticleEmitter> emitters;\r
+ private BoundingBox bounds;\r
+ private boolean ownsTexture;\r
\r
public ParticleEffect () {\r
emitters = new Array(8);\r
emitters.get(i).start();\r
}\r
\r
+ public void reset () {\r
+ for (int i = 0, n = emitters.size; i < n; i++)\r
+ emitters.get(i).reset();\r
+ }\r
+\r
public void update (float delta) {\r
for (int i = 0, n = emitters.size; i < n; i++)\r
emitters.get(i).update(delta);\r
public boolean isComplete () {\r
for (int i = 0, n = emitters.size; i < n; i++) {\r
ParticleEmitter emitter = emitters.get(i);\r
- if (emitter.isContinuous()) return false;\r
if (!emitter.isComplete()) return false;\r
}\r
return true;\r
emitters.get(i).setFlip(flipX, flipY);\r
}\r
\r
+ public void flipY () {\r
+ for (int i = 0, n = emitters.size; i < n; i++)\r
+ emitters.get(i).flipY();\r
+ }\r
+\r
public Array<ParticleEmitter> getEmitters () {\r
return emitters;\r
}\r
} catch (IOException ex) {\r
throw new GdxRuntimeException("Error saving effect: " + file, ex);\r
} finally {\r
- try {\r
- if (output != null) output.close();\r
- } catch (IOException ex) {\r
- }\r
+ StreamUtils.closeQuietly(output);\r
}\r
}\r
\r
} catch (IOException ex) {\r
throw new GdxRuntimeException("Error loading effect: " + effectFile, ex);\r
} finally {\r
- try {\r
- if (reader != null) reader.close();\r
- } catch (IOException ex) {\r
- }\r
+ StreamUtils.closeQuietly(reader);\r
}\r
}\r
\r
}\r
\r
public void loadEmitterImages (FileHandle imagesDir) {\r
+ ownsTexture = true;\r
for (int i = 0, n = emitters.size; i < n; i++) {\r
ParticleEmitter emitter = emitters.get(i);\r
String imagePath = emitter.getImagePath();\r
\r
/** Disposes the texture for each sprite for each ParticleEmitter. */\r
public void dispose () {\r
+ if (!ownsTexture) return;\r
for (int i = 0, n = emitters.size; i < n; i++) {\r
ParticleEmitter emitter = emitters.get(i);\r
emitter.getSprite().getTexture().dispose();\r
}\r
}\r
+ \r
+ /** Returns the bounding box for all active particles. z axis will always be zero. */\r
+ public BoundingBox getBoundingBox () {\r
+ if (bounds == null) bounds = new BoundingBox();\r
+\r
+ BoundingBox bounds = this.bounds;\r
+ bounds.inf();\r
+ for (ParticleEmitter emitter : this.emitters)\r
+ bounds.ext(emitter.getBoundingBox());\r
+ return bounds;\r
+ }\r
}\r