2
我曾經爲我的應用使用SimpleBaseGameActivity,一切正常,但現在我想在應用中添加一些廣告,所以我嘗試使用LayoutGameActivity。但是我得到的渲染視圖是完全黑色的,我不知道爲什麼。這是我的代碼:AndEngine:使用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。