3

当用户按下菜单按钮(暂停游戏)时,我试图让暂停菜单出现。游戏确实成功暂停,但没有任何东西绘制......也许它在我的 GLSurfaceView 下方绘制?这是我的代码。

public class GameActivity extends Activity {

private GLSurfaceView mGLSurfaceView;
private static final String TAG = "Game";
private MainGamePanel mGame;

private View mPauseMessage = null;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    SharedPreferences prefs = getSharedPreferences("GameSettings", MODE_PRIVATE);

    setContentView(R.layout.main);
    mGLSurfaceView = (GLSurfaceView) findViewById(R.id.glsurfaceview);
    mPauseMessage = findViewById(R.id.pausedMessage);

    mGLSurfaceView.setEGLConfigChooser(false); // 16 bit, no z-buffer

    mGame = new MainGamePanel();
    mGame.setSurfaceView(mGLSurfaceView);

    ....
    mGLSurfaceView.setRenderer(mGame.getRenderer());

}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    boolean result = true;
    if (keyCode == KeyEvent.KEYCODE_MENU) {
        if (mGame.isPaused()) {
            this.resume();
            if (mPauseMessage != null) {
                mPauseMessage.setVisibility(View.GONE);
            }
        } else {
            this.pause();
            if (mPauseMessage != null) {
                mPauseMessage.setVisibility(View.VISIBLE);
            }
        }
    }
    return result;
}

protected void pause() {
    super.onPause();

    mGame.onPause();
    mGLSurfaceView.onPause();
}


protected void resume() {
    super.onResume();

    mGame.onResume();
    mGLSurfaceView.onResume();
}

从我的 XML 中:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<android.opengl.GLSurfaceView xmlns:android="http://schemas.android.com/apk/res/android" 
            android:id="@+id/glsurfaceview"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
    />
    <LinearLayout
        android:id="@+id/pauseMenu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone">
    <ImageView 
    android:id="@+id/pausedMessage"
    android:src="@drawable/pause"
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:layout_gravity="center"/>
</LinearLayout>
</FrameLayout>
4

2 回答 2

3

也许你在某处有一句话说:

mGLSurfaceView.setZOrderOnTop(true);

它会覆盖 OpenGL 以在任何内容之上绘制,即使您的 RelativeLayout 中有其他视图。如果你有的话,试着评论一下。

否则你可以试试这个:(谢谢user2610335)

mGLSurfaceView.setZOrderOnTop(false)
于 2012-08-25T12:09:12.997 回答
0

我有一个类似的问题。但在我的情况下,pauseMenu 是不可见的,但没有消失。当我将其更改为 GONE 时,一切正常。但这仅发生在某些设备上。也许试试 View.bringToFront()

于 2012-10-05T16:18:04.970 回答