3

私は 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);
    }

このエラーを自分で解決しようとしたので、すでに試しました:

  1. カメラの FillResolutionPolicy() を設定しますが、結果には影響しません。
  2. 背景を BitmapTextureAtlas、BitmapTextureAtlasTextureRegionFactory.createFromAsset として作成します。
  3. attachChild の代わりに mEngine.getScene().setBackground を呼び出す
  4. 別の API レベルで Android 仮想デバイスを再作成します (16、15 を試行)

また、AndEngine フォーラムには、私が答えを見つけられなかったスレッドがあります

4

5 に答える 5

1

これを試して

myCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);

代わりは

myCamera = new Camera(800, 480, CAMERA_WIDTH, CAMERA_HEIGHT);
于 2012-08-18T05:49:42.520 に答える
1

問題の一部はここにあるかもしれません

public void onCreateResources(
        OnCreateResourcesCallback pOnCreateResourcesCallback)

メソッドの最後で呼び出すpOnCreateResourcesCallback必要がありますOnCreateResources

于 2012-08-20T13:23:13.620 に答える
1

コードにいくつかの間違いがあります

1) myCamera = new Camera(800, 480, CAMERA_WIDTH, CAMERA_HEIGHT); 1 番目と 2 番目の引数は、位置 x と y です。だからあなたは好きにするべきです

myCamera = 新しいカメラ(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);

2) CameraOptions で使用

new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), myCamera);

3) BitmapTexture をロードするには、使用する必要がありますBitmapTextureAtlasTextureRegionFactory

例えば。

BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
BitmapTextureAtlas bitmapTextureAtlas = new BitmapTextureAtlas(
        getTextureManager(), width_of_image, height_of_image,
        TextureOptions.BILINEAR //Or any TextureOpion you want.
);
ITextureRegion texture = BitmapTextureAtlasTextureRegionFactory
    .createFromAsset( bitmapTextureAtlas, this, "file_name.png", x_position, y_position);

bitmapTextureAtlas.load();
于 2012-08-22T06:05:24.250 に答える
1

私には、OpenGLの問題のように見えます。RenderOptions を見てみましょう。呼び出すことで取得できengineOptions.getRenderOptions();ます。そこで、さまざまなレンダリング オプションを微調整できます。

とにかく、あなたの Camera コンストラクターは非常に奇妙です。それによって何を達成しようとしていますか? 通常のパラメータは driver613 が言った通りです。また、CAMERA_WIDTH と CAMERA_HEIGHT の値が入れ替わっているようです。私が間違っていなければ、Android はデバイスの向きを処理するので、幅はデバイスの現在の向きの幅に実際に対応します。

于 2012-08-20T11:17:23.057 に答える