I am making a game for Android using AndEngine. Right now I’m trying to figure out how to make explosion sprites appear on the scene and then be removed X seconds after. Here is my explosion class:
public class Explosion extends Sprite {
public Explosion(float pX, float pY, ITextureRegion pTextureRegion, VertexBufferObjectManager pVertexBufferObjectManager) {
super(pX, pY, pTextureRegion, pVertexBufferObjectManager);
}
}
Now what I want to do to this class to make it different from a regular Sprite object is for it to appear, then be destroyed after a certain amount of time. How do I accomplish this using the AndEngine?
EDIT: If it’s possible to pull this off without having to create a custom Explosion class extending Sprite then I would prefer to do it that way since it would be neater.
Also note that there will be multiple explosions on screen at once being created at different times so I want each explosion to have their own individual lifespans.
There are several techniques you could use depending on your needs. If you explosion is animated, I’d just use an AnimatedSprite with an IAnimationListener to trap when the animation changes frames and/or is finished and then remove the explosion sprite.
Or, you could use a DelayModifier – I use one of these to “dissolve a rock”
Or, you could use just about any other Modifier – like a moving Modifier like say a QuadraticBezierCurveMoveModifier, or a Modifer like an AlphaModifier.
Regardless of the Modifier used, you attach a IEntityModifierListener() and in the onModifierFinished do your clean up of your explosion.
The following code uses that technique to “fade” a score off the game board
HTH
Here is an example of the DelayModifier – same basic structure