I am trying to create my first game for android. I currently have a title page with some graphics and a ‘start’ button.
What I am trying to do is load the game once the start button is pressed.
Here is my activity code:
public class TitlePage extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setContentView(new TitlePageView(this));
}
The class TitlePageView deals with loading & placing the images on the canvas, checks if the button is pressed and draws some balls floating around the screen.
Once the button is pressed, I don’t really need anything at all from the TitlePageView class. Is there a way of deleting the current view, and calling setContentView() with a different view?
I think you have implemented your own SurfaceView class to show the game content, i.e.
then in your
TitlePageActivity, initilize an instance of the GameView, like:When you want to show your game, simply call
setContentView(mGameView);Of course, you may call something like
mGameView.start()to start the game.