Menu for a game

Put your problem here if it does not fit any of the other categories.

Menu for a game

Postby jasonpeinko » Wed Nov 12, 2008 12:44 am

Im finishing up my first simple game, but I need to make a menu for it, what is the best way to do this? Also what about making an options page?

The way i tried to do it was to create two separate layouts, but the game portion does not do it when I tried it like this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. setContentView(R.layout.menu);
  2.  
  3.        
  4.  
  5.         start = (Button) findViewById(R.id.Start);
  6.  
  7.         start.setOnClickListener(new Button.OnClickListener()
  8.  
  9.         {
  10.  
  11.                 public void onClick(View view)
  12.  
  13.             {
  14.  
  15.                 setContentView(R.layout.main);
  16.  
  17.         // get handles to the LunarView from XML, and its LunarThread
  18.  
  19.             mGameView = (GameView) findViewById(R.id.game);
  20.  
  21.             mGameThread = mGameView.getThread();
  22.  
  23.  
  24.  
  25.             // set up a new game
  26.  
  27.             mGameThread.setState(GameThread.STATE_READY);
  28.  
  29.             Log.w(this.getClass().getName(), "SIS is null");
  30.  
  31.             }
  32.  
  33.         });
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
Last edited by jasonpeinko on Wed Nov 12, 2008 2:45 am, edited 1 time in total.
jasonpeinko
Junior Developer
Junior Developer
 
Posts: 21
Joined: Wed Nov 05, 2008 7:30 am

Top

Postby Quetzalcoatl » Wed Nov 12, 2008 2:34 am

Kick off your 2nd view by using an intent:

Code: Select all
Intent myIntent = new Intent(this, HighscoreView.class);
startActivity(myIntent);


Also look into functions such as this for your menu:

Code: Select all
@Override
   public boolean onCreateOptionsMenu(Menu menu) {
      // TODO Auto-generated method stub
      super.onCreateOptionsMenu(menu);
      
      menu.add(0, GAME_VIEW, 0, R.string.game_view);
      
      return true;
   }
Image
Quetzalcoatl
Senior Developer
Senior Developer
 
Posts: 129
Joined: Sat Oct 18, 2008 8:21 pm
Location: near Manchester, UK

Postby jasonpeinko » Wed Nov 12, 2008 2:46 am

My second view is in a java file, it is based of [s]mrshowflakes[/s] MrSnowflakes example.

[mod]It's MrSnowflake :p
jasonpeinko
Junior Developer
Junior Developer
 
Posts: 21
Joined: Wed Nov 05, 2008 7:30 am

Postby Quetzalcoatl » Wed Nov 12, 2008 2:52 am

Yeah, so's mine. I've not seen Mr.Snowflake's example so he's probably the best one to answer this.
Image
Quetzalcoatl
Senior Developer
Senior Developer
 
Posts: 129
Joined: Sat Oct 18, 2008 8:21 pm
Location: near Manchester, UK

Postby jasonpeinko » Wed Nov 12, 2008 3:27 am

why do you call highscore.class then?
jasonpeinko
Junior Developer
Junior Developer
 
Posts: 21
Joined: Wed Nov 05, 2008 7:30 am

Postby MrSnowflake » Wed Nov 12, 2008 8:55 am

If you are implementing a game, I woudn't use different Activities and Views. I'd just draw everything in the draw routine. This way, all your graphics will have the same look and feel. The down side is: this is a lot more work, as you have to implement your own 'buttons' and stuff. But the result would be nicer, as I don't know any console game which opens an OS dialog to select the type of game they want to play :).
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top

Postby Quetzalcoatl » Wed Nov 12, 2008 9:21 am

jasonpeinko wrote:why do you call highscore.class then?


class highscore {} is in a different java file (it is a highscore list that has a different menu etc). I have 2 views, 1 for the main game & running score and another for the highscore list. I just use intents to switch between the 2 as suggested by the docs ('each view should be in its own activity' etc).
Image
Quetzalcoatl
Senior Developer
Senior Developer
 
Posts: 129
Joined: Sat Oct 18, 2008 8:21 pm
Location: near Manchester, UK

Postby jasonpeinko » Wed Nov 12, 2008 5:05 pm

MrSnowflake wrote:If you are implementing a game, I woudn't use different Activities and Views. I'd just draw everything in the draw routine. This way, all your graphics will have the same look and feel. The down side is: this is a lot more work, as you have to implement your own 'buttons' and stuff. But the result would be nicer, as I don't know any console game which opens an OS dialog to select the type of game they want to play :).

lol, stupid typo in your name :)
That was my backup plan.

Is there a way to get the android button images?
jasonpeinko
Junior Developer
Junior Developer
 
Posts: 21
Joined: Wed Nov 05, 2008 7:30 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 17 guests