Game Development Reference
In-Depth Information
private GLSurfaceView mGLSurfaceView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGLSurfaceView = new GLSurfaceView(this);
try {
mGLSurfaceView.setRenderer(new CubeRenderer(true));
setContentView(mGLSurfaceView);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected void onPause() {
// Ideally a game should implement onResume() and onPause()
// to take appropriate action when the activity loses focus
super.onPause();
mGLSurfaceView.onPause();
}
@Override
protected void onResume() {
super.onResume();
mGLSurfaceView.onResume();
}
}
When the application loses focus or resumes, the onPause() or onResume() method will be called,
respectively. These methods delegate to the surface view ( GLSurfaceView ) to take the appropriate action,
such as saving application state or suspending/resuming the rendering process.
Surface View
The class GLSurfaceView (see Listing 5-3) defines the surface where the tumbling cubes animation will
take place. The class constructor starts by initializing a callback to receive notifications when the surface
is changed, created, or destroyed:
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
By implementing SurfaceHolder.Callback and calling SurfaceHolder.addCallback() , the class will
receive the events:
Search WWH ::




Custom Search