この記事は、私が前に書いたTexturePackerに関する記事を補足したものです。 私がゲーム開発でTexturePacker を使用するとき、ITiledTextureRegionの取得に苦戦していました。 既定では、 AndEngine Texture Packer拡張ではget(id) メソッドを使ってITextureRegion を取得する方法しかなかったからです(この見解は間違っているかもしれないでご了承ください)。
以下のようなspriteがあり、それをTexturePackerで生成されたテクスチャに配置したいとしましょう:
見て分かるように、2行4列となっています。ではこのsprite用に、どうやってITiledTextureRegionを簡単に読み込めるのでしょうか? AndEngine Texture Packer 拡張を編集して、ITiledTextureRegionを読み込むための独自メソッドを追加するのです。public ITiledTextureRegion get(int id, int columns, int rows) { TexturePackerTextureRegion localTexturePackTextureRegion = (TexturePackerTextureRegion)this.mIDMapping.get(id); return TiledTextureRegion.create(localTexturePackTextureRegion.getTexture(), (int)localTexturePackTextureRegion.getTextureX(), (int)localTexturePackTextureRegion.getTextureY(), (int)localTexturePackTextureRegion.getWidth(), (int)localTexturePackTextureRegion.getHeight(), paramInt2, rows, localTexturePackTextureRegion.isRotated()); }これで、get(id, columns, rows)メソッドを使って簡単にITiledTextureRegionを読み込めます
yourTiledRegion = yourTexturePackLibrary.get(id, columns, rows);
この方法で、TexturePackerを使ってすばやくtiled spritesを作成できます。
警告: タイル領域の読み込みでは、回転はサポートされていません!
上記のコードを正しく使用して領域を読み込むには、TexturePacker で回転オプションを無効にする必要があります!