Class ParticleEffectComponent

java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.ParticleEffectComponent
All Implemented Interfaces:
com.badlogic.gdx.utils.Json.Serializable

public class ParticleEffectComponent extends Component
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.

  • 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.
      Overrides:
      create in class Component
    • 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 rendering
      delta - delta time value used to update the particle effects
    • startEffect

      public void startEffect(ParticleService.ParticleEffectType effectType)
      Starts a ParticleEffect on an entity, enabling this component to control it throughout its lifecycle
      Parameters:
      effectType - type of ParticleEffect to be added to the entity
    • stopEffect

      public void stopEffect(ParticleService.ParticleEffectType effectType)
      Stops rendering an effect on the entity, freeing the effect and giving it back to the ParticleEffectPool. This will also remove the effect from the List of effects to be controlled by this component.
      Parameters:
      effectType - type of ParticleEffect to be stopped
    • stopEffectCategory

      public void stopEffectCategory(String category)
      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 their ParticleEffectPools and removing them from the List 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

      public boolean effectExists(ParticleService.ParticleEffectType effectType)
      Determines whether a ParticleEffect is being tracked by this component with the same type as the given ParticleService.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.
      Overrides:
      dispose in class Component