Package com.csse3200.game.particles
Class ParticleEffectRenderer
java.lang.Object
com.csse3200.game.particles.ParticleEffectRenderer
- All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable
,Renderable
,Comparable<Renderable>
public class ParticleEffectRenderer
extends Object
implements Renderable, com.badlogic.gdx.utils.Disposable
Renders a particle effect and frees it when completed.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionParticleEffectRenderer
(com.badlogic.gdx.graphics.g2d.ParticleEffectPool.PooledEffect pooledEffect) Initialise to render a given pooled particle effect on PARTICLE_LAYER layer.ParticleEffectRenderer
(com.badlogic.gdx.graphics.g2d.ParticleEffectPool.PooledEffect pooledEffect, int layer) Initialise to render a given pooled particle effect on a specified layer. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Allows the completion of the particle effect.int
void
dispose()
Frees the particle effect from its pool and unregisters this from the render service.com.badlogic.gdx.graphics.g2d.ParticleEffect
Get the underlying ParticleEffect.int
getLayer()
Layer to be rendered in.float
Z index controls rendering order within a layer.boolean
isValid()
Returns whether the underlying particle effect has completed.void
render
(com.badlogic.gdx.graphics.g2d.SpriteBatch batch) Updates and renders the particle effect.void
setPosition
(float x, float y) Sets the position of the particle effect.void
setPosition
(com.badlogic.gdx.math.Vector2 position) Sets the position of the particle effect.
-
Field Details
-
PARTICLE_LAYER
public static final int PARTICLE_LAYER- See Also:
-
-
Constructor Details
-
ParticleEffectRenderer
public ParticleEffectRenderer(com.badlogic.gdx.graphics.g2d.ParticleEffectPool.PooledEffect pooledEffect, int layer) Initialise to render a given pooled particle effect on a specified layer. Requires the render service to be initialised.- Parameters:
pooledEffect
- the particle effect to be rendered.layer
- the layer to render to.
-
ParticleEffectRenderer
public ParticleEffectRenderer(com.badlogic.gdx.graphics.g2d.ParticleEffectPool.PooledEffect pooledEffect) Initialise to render a given pooled particle effect on PARTICLE_LAYER layer.- Parameters:
pooledEffect
- the particle effect to be rendered.
-
-
Method Details
-
render
public void render(com.badlogic.gdx.graphics.g2d.SpriteBatch batch) Updates and renders the particle effect. If the effect is complete, will dispose.- Specified by:
render
in interfaceRenderable
- Parameters:
batch
- Batch to render to.
-
getEffect
public com.badlogic.gdx.graphics.g2d.ParticleEffect getEffect()Get the underlying ParticleEffect. Null if completed.- Returns:
- the particle effect
-
compareTo
- Specified by:
compareTo
in interfaceComparable<Renderable>
-
getZIndex
public float getZIndex()Description copied from interface:Renderable
Z index controls rendering order within a layer. Higher Z index is drawn on top.- Specified by:
getZIndex
in interfaceRenderable
- Returns:
- Z index
-
getLayer
public int getLayer()Description copied from interface:Renderable
Layer to be rendered in. Higher layers will be rendered on top of lower layers.- Specified by:
getLayer
in interfaceRenderable
- Returns:
- layer
-
setPosition
public void setPosition(com.badlogic.gdx.math.Vector2 position) Sets the position of the particle effect.- Parameters:
position
- the position to set to.
-
setPosition
public void setPosition(float x, float y) Sets the position of the particle effect.- Parameters:
x
- the x coordinate.y
- the y coordinate.
-
allowCompletion
public void allowCompletion()Allows the completion of the particle effect. -
isValid
public boolean isValid()Returns whether the underlying particle effect has completed.- Returns:
- true if the particle effect has completed.
-
dispose
public void dispose()Frees the particle effect from its pool and unregisters this from the render service.- Specified by:
dispose
in interfacecom.badlogic.gdx.utils.Disposable
-