Package com.csse3200.game.components
Class ParticleEffectComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.ParticleEffectComponent
- All Implemented Interfaces:
com.badlogic.gdx.utils.Json.Serializable
Component which can be added to entities allowing them to have
ParticleEffect
rendering on them and attached
to their body. This also enables the ParticleService
to keep track of these entities, rendering their effects
in the game loop.
This component also allows multiple particle effects to be rendered on a single entity ct the one time.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new component with an empty list of effects to render. -
Method Summary
Modifier and TypeMethodDescriptionvoid
create()
Adds event listeners to the component, allowing for effects to be stopped and started.void
dispose()
Disposes of the component, freeing all effects and removing the component from the entity.boolean
effectExists
(ParticleService.ParticleEffectType effectType) Determines whether aParticleEffect
is being tracked by this component with the same type as the givenParticleService.ParticleEffectType
.int
Gets the number of effects that are currently being tracked by the component.void
render
(com.badlogic.gdx.graphics.g2d.SpriteBatch batch, float delta) Renders all the effects that are being managed by the component for this entity.void
startEffect
(ParticleService.ParticleEffectType effectType) Starts aParticleEffect
on an entity, enabling this component to control it throughout its lifecyclevoid
Stops all of the particle effects for this entity, freeing the effects back to theirParticleEffectPool
s and removing them from theList
of effects being tracked.void
stopEffect
(ParticleService.ParticleEffectType effectType) Stops rendering an effect on the entity, freeing the effect and giving it back to theParticleEffectPool
.void
stopEffectCategory
(String category) Stops all particle effects by category in the entity's list of effectsMethods inherited from class com.csse3200.game.components.Component
earlyUpdate, getEntity, read, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update, write
-
Constructor Details
-
ParticleEffectComponent
public ParticleEffectComponent()Creates a new component with an empty list of effects to render.
-
-
Method Details
-
create
public void create()Adds event listeners to the component, allowing for effects to be stopped and started. -
render
public void render(com.badlogic.gdx.graphics.g2d.SpriteBatch batch, float delta) Renders all the effects that are being managed by the component for this entity.- Parameters:
batch
- sprite batch to use while renderingdelta
- delta time value used to update the particle effects
-
startEffect
Starts aParticleEffect
on an entity, enabling this component to control it throughout its lifecycle- Parameters:
effectType
- type ofParticleEffect
to be added to the entity
-
stopEffect
Stops rendering an effect on the entity, freeing the effect and giving it back to theParticleEffectPool
. This will also remove the effect from theList
of effects to be controlled by this component.- Parameters:
effectType
- type ofParticleEffect
to be stopped
-
stopEffectCategory
Stops all particle effects by category in the entity's list of effects- Parameters:
category
- category of particle effects
-
stopAllEffects
public void stopAllEffects()Stops all of the particle effects for this entity, freeing the effects back to theirParticleEffectPool
s and removing them from theList
of effects being tracked. -
getNumEffects
public int getNumEffects()Gets the number of effects that are currently being tracked by the component.- Returns:
- number of effects being tracked by this component.
-
effectExists
Determines whether aParticleEffect
is being tracked by this component with the same type as the givenParticleService.ParticleEffectType
.- Parameters:
effectType
- type of particle effect- Returns:
- whether that particle is being tracked
-
dispose
public void dispose()Disposes of the component, freeing all effects and removing the component from the entity.
-