Question

I am currently making a game, the game has a start screen and the main game screen.

My question is what is the best way to switch between the two views.

The start screen consists of just a couple of buttons one being "start game", when this is clicked GLsurface view to be created.

If i create the GLsurface view at the begining and bind the renderer here then anything from the GL surface view is displayed on top of the start up screen.

I thought i could create a viewflipper which would default to the start screen and then just create the glsurface view within the onclick method for the start button, but this doesnt seem to like having the GLsurface view in it.

Does viewFlipper support Glsurface view or is there a better way round this.

Thanks.

Was it helpful?

Solution

The easiest way is to use two activities, and just switch between them.

The trouble here is that ViewFlipper can only affect the "view" part of the GLSurfaceView, which is just a transparent hole. The surface where the GL rendering happens is composited separately, behind the layer with the view content, so it cannot be animated this way.

An example of using two activities in a GL game can be found in Android Breakout, which uses one activity for configuration and "start", and another for the game itself.

If you really want the ViewFlipper animation you could render into a TextureView, but your app would have to handle a number of things that GLSurfaceView does for you. TextureView is also less efficient than SurfaceView.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top