LoginSignup
0
0

More than 5 years have passed since last update.

AndEngineでTexturePackerを使う

Posted at

AndEngineでTexturePackerを扱うメモ

TexturePacker側

1.メニューの[File]-[New Project]を選択
2.下記画面でAndEngineを選択
image

3.Max Size W とHをそれぞれ1024にしておく。(AndEngineで扱える最大テクスチャサイズが、多くの端末において1024x1024であるため。)
image

3.リーソースにしたい画像を突っ込む
ドラッグして入れていく。フォルダをドラッグするとフォルダにある画像を全部読み込んでくれる

image

4.[Publish sprite sheet] をクリックして、保存する。ここではプロジェクト内のassetsフォルダにgfxという名前のフォルダを作ってそこに保存する。

1.hoge.png
2.hoge.xml
3.hoge.java

この3つのファイルが保存される。
hoge.javaファイルでは、それぞれの画像名にIDを割り当てています。
中身はこんな感じです。

hoge.java
package Texture;

public interface hoge
{
    public static final int ICONSHOCK_REAL_VISTA_MOBILE_ANDROID_PLATFORM_ICO_ID = 0;
    public static final int ANDROID_ID = 1;
    public static final int ANDROID_ICO_BY_GIOVANEFUORI_D6M8COY_ID = 2;
}

AndEngineで読み込む

以下にコードを示します。

インポート部分

import org.andengine.util.texturepack.TexturePack;
import org.andengine.util.texturepack.TexturePackLoader;
import org.andengine.util.texturepack.TexturePackTextureRegionLibrary;
import org.andengine.util.texturepack.exception.TexturePackParseException;

読み込み部分

    TexturePackTextureRegionLibrary tpl = null;
    TexturePack tp = null;

    try {
      tp = new TexturePackLoader(getAssets(), 
          getTextureManager()).loadFromAsset("gfx/hoge.xml", "gfx");
      tp.loadTexture();
      tpl = tp.getTexturePackTextureRegionLibrary();
    } catch (final TexturePackParseException e) {
      Logger.d(e.getMessage());
    }

    //それぞれのテクスチャの読み込み
    ITextureRegion texture = tpl.get(hoge.ANDROID_ID);

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0