I am developing a simple game which is totally based on animation. For this app, I am using AndEngine SDK. I am totally new in developing games in Android. I googled it lot, but all articles are so advanced and that are of no use for me in this app.
My Questions:
1.How can I perform loop animation with specific delay in each animation?
Here is my code:
final Sprite playButton = new Sprite(centerX, CAMERA_HEIGHT - 500, mPlayButton, getVertexBufferObjectManager());
final ScaleModifier scale = new ScaleModifier(0.5f, 1, 1.1f, 1f, 1.1f);
LoopEntityModifier scalePlayButton = new LoopEntityModifier(scale);
playButton.registerEntityModifier(scalePlayButton);
mScene.attachChild(playButton);
Now, I want specific delay in each scale animation performing in a loop.
2.If I don't use LoopEntityModifier, then how can I perform scale animation after specific delay. For this to achieve, here is my code:
final Sprite playButton = new Sprite(centerX, CAMERA_HEIGHT - 500, mPlayButton, getVertexBufferObjectManager());
final ScaleModifier scale = new ScaleModifier(0.5f, 1, 1.1f, 1f, 1.1f);
scale.addModifierListener(new IModifier.IModifierListener<IEntity>() {
@Override
public void onModifierStarted(IModifier<IEntity> pModifier, IEntity pItem) {
}
@Override
public void onModifierFinished(IModifier<IEntity> pModifier, IEntity pItem) {
playButton.registerEntityModifier(scale);
}
});
playButton.registerEntityModifier(scale);
mScene.attachChild(playButton);
But, it is not starting animation again once I attachChild to scene.
Please let me know where I am going wrong.
Thanks!
You can achieve it by using DelayModifier
class with the combination of SequenceEntityModifier
and LoopEntityModifier
from AndEngine. Here is code snippet:
final Sprite playButton = new Sprite(centerX, CAMERA_HEIGHT - 500, mPlayButton, getVertexBufferObjectManager());
SequenceEntityModifier scaleSequence = new SequenceEntityModifier(
new ScaleModifier(0.2f, 1f, 1.07f),
new ScaleModifier(0.2f, 1.07f, 1f),
new DelayModifier(2f)
);
LoopEntityModifier scaleLoopModifier = new LoopEntityModifier(scaleSequence);
playButton.registerEntityModifier(scaleLoopModifier);
mScene.attachChild(playButton);
Hope it helps you!