2

以前はアプリに SimpleBaseGameActivity を使用していましたが、すべて問題ありませんでしたが、アプリに広告を追加したいので、LayoutGameActivity を使用しようとしました。しかし、レンダー ビューが完全に黒くなり、その理由がわかりません。それが私のコードです:

public class AcGame extends LayoutGameActivity {
    [...]
    @Override
    protected int getLayoutID() {
        return R.layout.ad;
    }

    @Override
    protected int getRenderSurfaceViewID() {
        return R.id.layout_render;
    }

    @Override
    public EngineOptions onCreateEngineOptions() {
        [...]
        return new EngineOptions(true, ScreenOrientation.PORTRAIT_FIXED, resolution, camera);
    }

    @Override
    public void onCreateResources(OnCreateResourcesCallback pOnCreateResourcesCallback) throws Exception {
        createResources();
        pOnCreateResourcesCallback.onCreateResourcesFinished();
    }

    @Override
    public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws Exception {
        pOnCreateSceneCallback.onCreateSceneFinished(createScene());
    }

    @Override
    public void onPopulateScene(Scene pScene, OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception {
        pOnPopulateSceneCallback.onPopulateSceneFinished();
    }

そして、それが私のレイアウトです:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">
    <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="top"
            android:id="@+id/layout_ad"
            >
        <Button
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:text="Ad Sample"/>
    </LinearLayout>
    <org.andengine.opengl.view.RenderSurfaceView
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center"
            android:id="@+id/layout_render"
            />

</LinearLayout>

デバッグしようとすると、EngineOptions が作成されていることがわかりますが、LayoutGameActivity のメソッドはどれも呼び出されませんでした ( onCreateResourcesonCreateSceneまたはonPopulateScene)。誰かが私が見逃したことを教えてもらえますか?

UPD: xmlでボタンを下に移動すると、シーンが表示されることがわかりました:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">
    <org.andengine.opengl.view.RenderSurfaceView
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center"
            android:id="@+id/layout_render"
            />
    <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="top"
            android:id="@+id/layout_ad"
            >
        <Button
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:text="Ad Sample"/>
    </LinearLayout>

</LinearLayout>

しかし、今はボタンが見えず、まだ SimpleBaseGameActivity を使用しているようです。

4

1 に答える 1

5

解決策を見つけました。(Simple)LayoutGameActivityを使用する場合は、 を使用する必要がありますRelativeLayout。また、LayoutGameActivityの代わりにを使用する場合はSimpleLayoutGameActivity、コールバックを使用することを忘れないでください!

于 2012-10-19T13:09:49.320 に答える