Particle Effects Code - UQdeco2800/2021-ext-studio-2 GitHub Wiki
Table of Contents
Enemies mount particle components
Particle effect component
ParticleRenderComponent.java Defines the loading path and loading time of the particle effect file. Through getZIndex()
drawing priority of the current entity. startEffect()
is used to determine whether to trigger particle effects.
public void create() {
super.create();
pe = new ParticleEffect();
pe.load(Gdx.files.internal(texturePath), Gdx.files.internal("images/particle"));
}
public float getZIndex() {
return 1;
}
public void startEffect() {
EffectStart = true;
}
protected void draw(SpriteBatch batch) {
if (EffectStart) {
// for situation the entity is disappeared but particle effect still exist.
Vector2 entityPosition = entity.getPosition();
if (!entity.getType().equals("Portal") && !entity.getType().equals("FlyingMonkey")) {
logger.info("Position = {}, entity = {}, disappear = {}, removeTexture = {}", entityPosition, entity, entity.isDisappear(), entity.isRemoveTexture());
}
pe.update(Gdx.graphics.getDeltaTime());
pe.setPosition(entityPosition.x, entityPosition.y);
pe.draw(batch);
if (pe.isComplete()) {
pe.reset();
}
particlePlayTime += timeSource.getDeltaTime();
}
}
Enemies mount particle components
The following is an example of entity mounted particle effects,this is very similar to how to mount animation render component
ParticleRenderComponent particle =
new ParticleRenderComponent("images/particle/plant2.party");
obstacle.addComponent(particle)
particle.startEffect();
Particles disappear
in Entity.java use etDisappearAfterParticle
set disappear to true. These variables play a role in removeAfterParticle()
and update()
.
public void setDisappearAfterParticle(float particleTime, DisappearType disappearType) {
this.disappear = true;
this.particleTime = particleTime;
this.disappearType = disappearType;
logger.debug("Setting disappear={} on entity {}", disappear, this);
}
public void setParticleTime(float particleTime) {
this.particleTime = particleTime;
}
use removeAfterParticle()
, set obstacles disappear after playing the particle for particleTime second. Is called by update()
.
public void removeAfterParticle() {
if (this.getComponent(ParticleRenderComponent.class).getParticlePlayTime() > particleTime) {
disposeExceptAnimationComponent();
}
}