私は AndEngine を初めて使用し、このチュートリアルに従ってハノイ ゲームを実装しようとしています。背景画像を gfx フォルダーに挿入し、すべての onCreateResources コードと onCreateScene コードを設定した後、アプリを実行しようとしましたが、この画像でわかるように、背景画像を表す三角形だけが表示されます。
これが私のコードです:
final int CAMERA_WIDTH = 480;
final int CAMERA_HEIGHT = 800;
public EngineOptions onCreateEngineOptions() {
myCamera = new Camera(800, 480, CAMERA_WIDTH, CAMERA_HEIGHT);
return new EngineOptions(false, ScreenOrientation.PORTRAIT_SENSOR,
new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT),
myCamera);
}
public ITextureRegion texture;
public void onCreateResources(
OnCreateResourcesCallback pOnCreateResourcesCallback)
throws Exception {
try {
// 1 - Set up bitmap textures
ITexture backgroundTexture = new BitmapTexture(
this.getTextureManager(), new IInputStreamOpener() {
public InputStream open() throws IOException {
return getAssets().open("gfx/background.png");
}
});
// 2 - Load bitmap textures into VRAM
backgroundTexture.load();
// 3 - Set up texture regions
this.mBackgroundTextureRegion = TextureRegionFactory
.extractFromTexture(backgroundTexture);
}
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback)
throws Exception {
// 1 - Create new scene
final Scene scene = new Scene();
Sprite backgroundSprite = new Sprite(0, 0, this.mBackgroundTextureRegion, getVertexBufferObjectManager());
scene.attachChild(backgroundSprite);
}
このエラーを自分で解決しようとしたので、すでに試しました:
- カメラの FillResolutionPolicy() を設定しますが、結果には影響しません。
- 背景を BitmapTextureAtlas、BitmapTextureAtlasTextureRegionFactory.createFromAsset として作成します。
- attachChild の代わりに mEngine.getScene().setBackground を呼び出す
- 別の API レベルで Android 仮想デバイスを再作成します (16、15 を試行)
また、AndEngine フォーラムには、私が答えを見つけられなかったスレッドがあります。