3 Replies - 184 Views - Last Post: 07 February 2012 - 10:10 PM Rate Topic: -----

Topic Sponsor:

#1 NantucketSleighride  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 92
  • Joined: 13-February 11

Theory/Practice behind games with multiple screens?

Posted 07 February 2012 - 08:00 PM

**Meant to post this in the general Java section, not the advanced. Honestly, I'm not even sure how it posted in the Advanced section since I'm 100% I was in the general section to start with. Sorry**

Quick question I've got.

To this point, I've been working on games with single screens. Simple hangman or pacman type games. You basically have one screen, and information just gets reset or changed and that's it.

*edit* - to clarify - I have sort of worked on "multiple" screens or views; but only in the sense of having a tile based map on screen that when the user moves off in a direction, the array of tiles is redrawn to represent that room. I've never done anything where the layout is entirely different.

However - I now desire to create a game with more than one screen. Let's say a tile game where you've got a map in the top corner and you can click on it to make it full screen - and then exit from it to go back to the game... Or say an inventory screen, or something like that.

My question is - what's the most commonly agreed on practice for doing something like this?

The ways I've thought of so far would be:

-have booleans representing each 'screen' and have an if loop that basically makes the program paint based on this. So perhaps something like:

if (mapEnlarged){
   //paint Map
}
else if (inventoryEnlarged){
   //paint Inventory
}
else{
   //paint main game screen
}



-have multiple JFrames where a new JFrame pops up over the game one (can't see this being a very good idea).

-draw the game in the background still, but draw stuff over it; so, for instance, the game pauses then goes through a loop like it did above, but instead of so many ifs, it just draws the game in the state it's in, and then goes through the if and draws over that.

Those are the routes I can think of. I'd like to finally try something simple. Maybe even just a Main Menu and then the Game Screen. I just really don'y know what the best way to begin on something like this is - since I'm sure there are some major draw backs to different methods, as well as advantage. Perhaps the best method isn't even something I've touched on.

Thanks in advance. I've learned a ton on this forum and I appreciate the help you guys give.

This post has been edited by Atli: 07 February 2012 - 09:35 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Theory/Practice behind games with multiple screens?

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1760
  • View blog
  • Posts: 2,693
  • Joined: 08-June 10

Re: Theory/Practice behind games with multiple screens?

Posted 07 February 2012 - 09:35 PM

* Moved to the Java forum *
Was This Post Helpful? 0
  • +
  • -

#3 Mylo  Icon User is offline

  • D.I.C Regular

Reputation: 135
  • View blog
  • Posts: 493
  • Joined: 11-October 11

Re: Theory/Practice behind games with multiple screens?

Posted 07 February 2012 - 10:09 PM

I guess the best way would be to use something like a LayeredPane so you can have several JPanels each drawing their own things.

If you are only using paint you don't really need a boolean to determine whats being draw (unless you have one thing taking up the whole scree at a time, then i'd go with your idea).

like

...drawgame
...if (inventoryopen)
   ... draw inventory



then you can get your mouse click event and use arithemic to get what you need

if (click intersects with inventory area)
    ... do whatever in inventory
else if (click intersects with 
    ... perform game click



ofcourse there is a problem of z-order here, since inventory would always take priority. So maybe you want an ArrayList<Menus> which are added in order of opening. This way you would click whatever is top first taking priority.

This being said, I might do something like this now, since I haven't figured out that layered pane yet

Hope that helps :)
That is just how I think of it anyway, though I have never done it before
Was This Post Helpful? 0
  • +
  • -

#4 Sheph  Icon User is online

  • D.I.C Addict
  • member icon

Reputation: 294
  • View blog
  • Posts: 777
  • Joined: 12-October 11

Re: Theory/Practice behind games with multiple screens?

Posted 07 February 2012 - 10:10 PM

Why not just draw every different screen you want on a JPanel and use CardLayout? Never create more than one JFrame unless you know what you are doing. You could have an Inventory class and an InventoryDrawer class which extends JPanel. The InventoryDrawer could be put anywhere you could put a JPanel, then it's just a matter of Layouts. CardLayout allows for 1 JPanel per screen and can switch between them at will.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1