質問

私はAndengineを使用してライブの壁紙を作成しています。ただし、onloadResources()メソッドでは、現在3つの異なるテクスチャをロードしています。

@Override
public void onLoadResources() {
    prefs = PhysicsWallpaperActivity.this.getSharedPreferences(SHARED_PREFS_NAME, 0);
    prefs.registerOnSharedPreferenceChangeListener(this);
    this.mAutoParallaxBackgroundTexture = new BitmapTextureAtlas(2048, 2048, TextureOptions.DEFAULT);
    this.mAutoParallaxImage1Texture = new BitmapTextureAtlas(2048, 2048, TextureOptions.DEFAULT);
    this.mAutoParallaxImage2Texture = new BitmapTextureAtlas(2048, 2048, TextureOptions.DEFAULT);

    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
    this.mParallaxLayerBackground = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAutoParallaxBackgroundTexture, this, "background.jpg", 0, 0);
    this.mParallaxLayerImage1 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAutoParallaxImage1Texture, this, "image1.jpg", 0, 0);
    this.mParallaxLayerImage2 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAutoParallaxImage2Texture, this, "image2.png", 0, 800);

    this.mEngine.getTextureManager().loadTexture(this.mAutoParallaxBackgroundTexture);  
    this.mEngine.getTextureManager().loadTexture(this.mAutoParallaxImage1Texture);               
    this.mEngine.getTextureManager().loadTexture(this.mAutoParallaxImag2Texture);               

}

これはこれを行う最も効率的な方法ではないと思います。しかし、すべてのbitmaptextureatlastexturegionfactorys 'images'が単一のbitmaptextureatlasを指している場合、それらの「画像」が同じ座標にある場合、画像は1つだけ電話しても互いに互いにロードされます。

問題の例はこちらです:

    @Override
 public void onLoadResources() {
    prefs = PhysicsWallpaperActivity.this.getSharedPreferences(SHARED_PREFS_NAME, 0);
    prefs.registerOnSharedPreferenceChangeListener(this);
    this.mAutoParallaxBackgroundTexture = new BitmapTextureAtlas(2048, 2048, TextureOptions.DEFAULT);

    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
    this.mParallaxLayerBackground = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAutoParallaxBackgroundTexture, this, "background.jpg", 0, 0);
    this.mParallaxLayerImage1 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAutoParallaxBackgroundTexture, this, "image1.jpg", 0, 0;
    this.mParallaxLayerImage2 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAutoParallaxBackgroundTexture, this, "image2.png", 0, 800);

    this.mEngine.getTextureManager().loadTexture(this.mAutoParallaxBackgroundTexture);               

}

^このようなコードをより効率的に見えるので、このようなコードを使用したいと思っていましたが、「Image1」と「Image2」は、1つだけ電話しても、互いの上に自動的にロードされます。

私はこれを正しい方法でやっていますか?または、より効率的な方法はありますか?

役に立ちましたか?

解決

テクスチャには複数のリソースを含めることができます。スプライトシートのように考えてください。または、大きな白い紙に写真を接着するようなものです。テクスチャ領域ごとに新しいテクスチャは必要ありません。たとえば、星画像、つまり250x250ピクセルと100x100ピクセルの宇宙船画像を持っているとします。これらの両方を512x256を測定するテクスチャーに置くことができます。 0、0に星(250x250)のテクスチャ領域(250x250)を作成します。次に、251、0の宇宙船の2番目のテクスチャ領域を作成します。

そのシナリオでは、他の画像が宇宙船を吹き飛ばすための残りの領域がまだあります。下の画像は、メモリで見ることができれば、テクスチャーがどのように見えるかを示しています。

texture with two resources added

お役に立てれば。

他のヒント

あなたのテクスチャーは巨大です!あなたはそれらをそんなに大きくする必要があると確信していますか?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top