@Override public void onCreateResources(OnCreateResourcesCallback pOnCreateResourcesCallback) throws IOException { loadGraphics(); loadFonts(); loadSounds(); pOnCreateResourcesCallback.onCreateResourcesFinished(); } private void loadGraphics() { } private void loadFonts() { } private void loadSounds() { }
private BitmapTextureAtlas yourTexture; private ITextureRegion yourTextureRegion; private void loadGraphics() { BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/"); yourTexture = new BitmapTextureAtlas(getTextureManager(), 256, 256, TextureOptions.DEFAULT); yourTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(yourTexture, this, "image.png", 0, 0); yourTexture.load(); }256x256 (ピクセル単位)のサイズのtexture を作成しています。 例えばtexture が必要なくなった場合など、好きな時にtextures の読み込みや読み込み解除をすることができます。
以下のような状況を考えてみましょう。Sceneが二つあり、各Sceneは独自のテクスチャを使用しています。 Sceneを切り替える際に、一方のテクスチャの読み込みを解除してもう一方のテクスチャを読み込みます。この際には既に作成したものと同じテクスチャを読み込むことができます (テクスチャ領域の初期化を最初から行う必要はありません)。結論:使用していないテクスチャの読み込みを解除することで、簡単にメモリ使用量を減らすことができます!
private Font yourFont; public void loadFonts() { FontFactory.setAssetBasePath("font/"); final ITexture fontTexture = new BitmapTextureAtlas(activity.getTextureManager(), 256, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA); yourFont = FontFactory.createFromAsset(getFontManager(), fontTexture, getAssets(), "font.ttf", 40, true, Color.BLACK); yourFont.load(); }
private Sound yourSound; public void loadSounds() { try { yourSound = SoundFactory.createSoundFromAsset(getEngine().getSoundManager(), this, "mfx/sound.ogg"); } catch (IOException e) { e.printStackTrace(); } }
andengineの音声再生に関する詳細情報が必要な場合は、この記事を参照してください。