\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
} 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