org.pixel.ext.ecs.component.AutoDisposeComponent Maven / Gradle / Ivy
package org.pixel.ext.ecs.component;
import org.pixel.commons.DeltaTime;
import org.pixel.ext.ecs.GameComponent;
/**
* Auto disposes the game object entity after the configured amount of seconds.
*/
public class AutoDisposeComponent extends GameComponent {
private final float seconds;
private float elapsed;
/**
* Constructor.
*
* @param seconds The amount of seconds to wait before disposing the game object entity.
*/
public AutoDisposeComponent(float seconds) {
super(AutoDisposeComponent.class.getSimpleName());
this.seconds = seconds;
this.elapsed = 0f;
}
@Override
public void update(DeltaTime delta) {
super.update(delta);
this.elapsed += delta.getElapsed();
if (elapsed >= seconds) {
this.getGameObject().dispose();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy