2ntブログ

スポンサーサイト

上記の広告は1ヶ月以上更新のないブログに表示されています。
新しい記事を書く事で広告が消せます。

AndEngine覚書

■onCreateResources内でリソース読み込み

BitmapTextureAtlas
ITextureRegion
はセット扱い。サンプルだと大体クラス変数


BitmapTextureAtlasの変数 = new BitmapTextureAtlas(this.getTextureManager(), 32, 32, TextureOptions.BILINEAR);
32, 32の部分は多分縦横。 getTextureManagerはSimpleGameActivityクラスの中にあるのか分からんけど普通に使える

ITextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.ITextureRegionのメンバ変数名, this, "読み込む画像.png", 横パネルの数, 縦パネルの数);
この辺は画像構成によって変わるけど一枚画像を読み込みたい場合(タイル上の画像じゃない場合)は0,0を指定すればOKっぽい

this.BitmapTextureAtlasの変数.load();
ロードすると画像読み込みされる(多分)


■CreateSceneでやること

final Sprite temp = new Sprite(10,10, this.mTempRegion, this.getVertexBufferObjectManager());
Spriteの第1,2引数は画面上のX,Y座標。mTempRegionはどのテクスチャを使うか(ITextureRegion)


final PhysicsHandler tempPhysicsHandler = new PhysicsHandler(temp);
物理演算ハンドラ?にスプライトを渡してやる

temp.registerUpdateHandler(tempPhysicsHandler);
スプライトの更新ハンドラとして物理演算用ハンドラ(?)を渡してやる

scene.registerUpdateHandler(new IUpdateHandler() {
@Override
public void reset() { }

@Override
public void onUpdate(final float pSecondsElapsed) {
if(temp.collidesWith(face)){
temp.setAlpha(0.5f);
}else{
temp.setAlpha(1.0f);
}
}
});
スプライトのcollidesWithメソッドに別のスプライト変数を渡してやるとコリジョン判定してくれる
trueかfalseで帰ってくるのでそれで判別



コメント
コメントの投稿
管理者にだけ表示を許可する