Load Animation with Texture Packer in andengine

纵饮孤独 提交于 2019-12-23 12:07:35

问题


I use Texture Packer. I have .pvr.ccz file there are 10 frames.

I need to create an AnimatedSprite with this animation, but TexturePacker extension return only TextureRegion files.

How I can create TiledTextureRegion from this file?


回答1:


public TiledTextureRegion getTiledTextureFromPack(String name) {
    TexturePackTextureRegionLibrary packer;
    TexturePack spritesheetTexturePack;
    try {
        spritesheetTexturePack = new TexturePackLoader(game.getTextureManager(), "packs/")
                .loadFromAsset(game.getAssets(), name + ".xml");
        spritesheetTexturePack.loadTexture();
        this.packer = spritesheetTexturePack.getTexturePackTextureRegionLibrary();
    } catch (final TexturePackParseException e) {
        Debug.e(e);
    }

    TexturePackerTextureRegion[] obj = new TexturePackerTextureRegion[this.packer
            .getIDMapping().size()];

    for (int i = 0; i < this.packer.getIDMapping().size(); i++) {
        obj[i] = this.packer.get(i);
    }

    TiledTextureRegion texture = new TiledTextureRegion(spritesheetTexturePack.getTexture(),
            obj);

    return texture;
}

I found solution



来源:https://stackoverflow.com/questions/9311149/load-animation-with-texture-packer-in-andengine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!