1

I'm new to AndEngine. I want to simply play an animation on the center of the screen by using sprite sheet (I'm using TexturePacker for creating sprite sheet) can anyone help me with this requirement?! I didn't find any good complete tutorial for the same! Thanks in advance.

Favas Kv
  • 2,961
  • 2
  • 28
  • 38

1 Answers1

2

First load Sprite sheet as follows:

 TexturePackLoader texturePackLoader = new TexturePackLoader(this.getAssets(), this.getTextureManager());
 TexturePack gameTexPack = texturePackLoader.loadFromAsset("gfx/JumpingJack.xml", "gfx/");
 gameTexPack.loadTexture();
 TexturePackTextureRegionLibrary mTextureRegionLibrary = gameTexPack.getTexturePackTextureRegionLibrary();

You can play animation of frames as follows:

public static AnimatedSprite getAnimatedSprite(int textRegId, int framesCount){ 
    int counter=0;

    ITextureRegion[] iTextureRegions = new ITextureRegion[framesCount];

    for(int i = 0; i < 4; i++){
        ITextureRegion textureRegion = GameActivity.activity.mTextureRegionLibrary.get(textRegId+i).deepCopy();
        iTextureRegions[counter] = textureRegion;
        counter++;
    }

    ITiledTextureRegion tiledTextureRegion = new TiledTextureRegion(iTextureRegions[0].getTexture(), iTextureRegions);
    AnimatedSprite animSprite = new AnimatedSprite(0, 0, tiledTextureRegion, GameActivity.activity.getVertexBufferObjectManager());
    return animSprite;
}
Rama
  • 1,156
  • 1
  • 7
  • 13