2012-05-02 6 views
2

ユーザーがメニューボタンを押したとき(ゲームを一時停止する)にポーズメニューを表示しようとしています。ゲームは正常に中断しますが、何も描画されません。おそらく、私のGLSurfaceViewの下に描画されていますか?ここに私のコードです。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> 

答えて

2

はたぶん、あなたはどこかのラインを言っている:

mGLSurfaceView.setZOrderOnTop(true); 

あなたが上に他のビューを持っていても、何の上に描画するOpenGLを上書きしますどのあなたのRelativeLayoutでそれの。あなたがそれを持っている場合、これをコメントアウトしてみてください。

0

私も同様の問題がありました。しかし、私の場合、pauseMenuはINVISIBLEでしたが、GONEはありませんでした。私がGONEに変更したとき、すべてうまくいった。しかし、それは一部のデバイスでのみ起こります。たぶん、View.bringToFront()を試してください

関連する問題