0

I want to do an "chain" or circular loop of animations as can be described below:

LABEL start do Anim1->Anim2->Anim3->Anim4 GOTO start

The above will do a circular loop: Anim1->Anim2->Anim3->Anim4 and back to Anim1 and so on.

I am not able to merge all the PNGs in one Texture because Andengine/Android is limited in loading the resources. However, when I split my initial large tile into 4 smaller tiles, everything works fine.

I tried to use an AnimationListener inside Anim1. When onAnimationFinished() is called, I detach Anim1, and run Anim2 and do this in chain of inner functions. However, when I am in Anim4, I do not know how to go back to the start and attach Anim1.

Note: All this problem could be solved if you know how I can pack a set of 150 PNGs that individually quite large but fit in a tile of 4096x4096 px.

Thank you for your help!

EDIT (following JiMMaR's proposed solution): I am using Texture Packer and the overall Texture exceeds 4096*4096, causing an OutOfMemory error on Android.

At the moment, I have split the Textures into four tiles and I four PNG tilemaps.

Shailen
  • 7,909
  • 3
  • 29
  • 37

2 Answers2

0

You can use 'Texture Packer' to see if all your images can fit in 4096 x 4096.

You can download Texture Packer from here. (NOTE: Texture Packer supports AndEngine data output too)

You can use "BuildableBitmapTextureAtlas" and "BlackPawnTextureAtlasBuilder" classes to pack your PNGs into one texture atlas.

Mazhar
  • 366
  • 1
  • 2
  • 13
  • You'll need to get the texturePackerExtension for AndEngine , also you shouldn't use a texture atlas larger than 2048 for compatibility reasons – Jimmar Nov 24 '12 at 23:31
  • Actually, I use TexturePacker! With all my PNGs, the size of the texture exceeds 4096 * 4096, and this causes an OutOfMemory error. If I split the Textures, I do not get this error. So, to overcome this limitation, I want to chain from Anim1 to Anim 2. How do I do that? – Shailen Nov 26 '12 at 00:26
  • Post your code block. It will help overcome the issue with alternatives. – Mazhar Nov 26 '12 at 08:02
0

You should post some code so we can see the implementation.

Try to use several AnimatedSprites with animation listeners in each one. This way you can start the animation of the next sprite in the onAnimationFinished() call.

private class AnimationLooperListener implements IAnimationListener{

    private AnimatedSprite nextSpriteToAnimate;

    public AnimationLooperListener(AnimatedSprite sprite){
        nextSpriteToAnimate = sprite;
    }

    /** other methods  are hidden */

    public void onAnimationFinished(AnimatedSprite sprite){
        sprite.setVisible(false);
        nextSpriteToAnimate.setVisible(true);
        nextSpriteToAnimate.animate(100, new AnimationLooperListener(sprite);
    }

}

AnimatedSprite sprite1 = new AnimatedSprite(0, 0, tiledTextureRegion, vertex);
AnimatedSprite sprite2 = new AnimatedSprite(0, 0, tiledTextureRegion, vertex);
AnimatedSprite sprite2 = new AnimatedSprite(0, 0, tiledTextureRegion, vertex);

AnimationLooperListener listener1 = new AnimationLooperListener(sprite2);
AnimationLooperListener listener2 = new AnimationLooperListener(sprite3);
AnimationLooperListener listener3 = new AnimationLooperListener(sprite1);

sprite1.animate(100, listener1);
sprite2.animate(100, listener2);
sprite3.animate(100, listener3);

This way, you have an animation loop, between several sprites that can be created using several TiledTextureRegions.

Orgmir
  • 383
  • 3
  • 8