我曾经在我的应用程序中使用 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 的方法被调用(onCreateResources
或onCreateScene
)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。