-
Notifications
You must be signed in to change notification settings - Fork 9
Particle Effects
ParticleComponent
is a subclass of RenderComponent
which can be attached to entities to allow them to produce particles, as specified by a ParticleEffectsConfig
.
A ParticleComponent has constructor ParticleComponent(ParticleEffectsConfig)
which takes a ParticleEffectsConfig
.
The following additional functions are defined within ParticleComponent
:
void startEffect(String effectName)
void stopEffect(String effectName)
These functions start and stop the effect of name effectName
within the config file. The effect will be centered on the entity (plus offset specified in the config file). If an effect which is not specified in the config is started or stopped, nothing will happen.
Below is an example of creating a ParticleEffect component:
var particleEffectsConfig = new ParticleEffectsConfig();
particleEffectsConfig.effectsMap = new ObjectMap<>();
particleEffectsConfig.effectsMap.put("effectName", "particle-effects/subdirectory/subdirectory/fileName.effect");
ParticleComponent particleComponent = new ParticleComponent(particleEffectsConfig);
entity.addComponent(particleComponent)
Below is an example of triggering a ParticleEffect component:
entity.getComponent(ParticleComponent.class).startEffect("effectName");
entity.getComponent(ParticleComponent.class).stopEffect("effectName");
classDiagram
class RenderComponent {
}
class ParticleEffect {
+dispose()
}
class ParticleComponent {
-effects: Map<string, ParticleEffect>
+create()
+draw()
+startEffect()
+stopEffect()
}
RenderComponent <|-- ParticleComponent
ParticleEffect ..|> Disposable
ParticleComponent o-- ParticleEffect
Below is a sequence diagram highlighting the call order of starting and then stoping a particle effect.
sequenceDiagram
Entity->>+EventHandler: trigger('startEffect', effectName)
EventHandler->>+ParticleComponent: startEffect(effectName)
ParticleComponent->>+ParticleEffect: start()
Entity->>+EventHandler: trigger('stopEffect', effectName)
EventHandler->>+ParticleComponent: stopEffect(effectName)
ParticleComponent->>+ParticleEffect: reset()
This is a simple config class for particle effects. It stores a mapping from effect names to their .effect file-path.
.effect files can be generated using the Libgdx Particle Editor. Documentation can be found here.
For organisational purposes, it is recommended particle effects are placed in a subdirectory of particle-effects
in the assets directory.
Escape Earth Game
Interaction Controller and Interactable Components
Game and Entity Configuration Files
Loading Game Configuration Files