uncle Lem
uncle Lem

Reputation: 5024

AndEngine: Black screen when using LayoutGameActivity

I used to use SimpleBaseGameActivity for my app and everything was ok, but now I want to add some ads into the app, so I tried to use LayoutGameActivity. But I get the render view is completely black and I don't know why. That's my code:

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();
    }

And that's my layout:

<?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>

When I'm trying to debug, I can see that EngineOptions are creating, but no one of the LayoutGameActivity's methods was called (onCreateResources, onCreateScene or onPopulateScene). Can someone tell me what I've missed?

UPD: I've found that if to move button in xml down, scene is showing:

<?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>

But now I can't see my button and all seems like I'm still using SimpleBaseGameActivity.

Upvotes: 2

Views: 1235

Answers (1)

uncle Lem
uncle Lem

Reputation: 5024

I've found the solution: If you want to use (Simple)LayoutGameActivity, you have to use RelativeLayout. Also if you use LayoutGameActivity instead of SimpleLayoutGameActivity, don't forget to use callbacks!

Upvotes: 5

Related Questions