aspose file tools*
The moose likes Game Development and the fly likes Creating my first game Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "Creating my first game" Watch "Creating my first game" New topic
Author

Creating my first game

Andy Joness
Greenhorn

Joined: Sep 15, 2009
Posts: 24
Hi, I've decided to try and create a simple 2D game in Java to learn about graphics and animation etc. However first I need some tips on the interface design.

What is the simplest/cleanest way of creating "pages"? I can't decide between jFrames (just setting visibility) and CardLayout. Is there a better way?

Secondly I am going to run it in fullscreen. How would I go about getting the frames/panels to automatically resize to the specified resolution? I plan on having a settings page with several resolutions available. The page contents(controls) need to automatically position themselves relative to the borders.

Lastly my method of using background images on frames involves instantiating a frame using this code:


Is this good, or is there a more efficient way? Cheers
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

Andy Joness wrote:What is the simplest/cleanest way of creating "pages"? I can't decide between jFrames (just setting visibility) and CardLayout. Is there a better way?

I wouldn't use JFrames. The user will notice the current frame disappearing and a new one reappearing. CardLayout is designed for this type of work, where you replace (a part of) the current user interface with something else.

Secondly I am going to run it in fullscreen. How would I go about getting the frames/panels to automatically resize to the specified resolution? I plan on having a settings page with several resolutions available. The page contents(controls) need to automatically position themselves relative to the borders.

Use GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(frame) to set the the JFrame called "frame" as the fullscreen window on your default screen.

Lastly my method of using background images on frames involves instantiating a frame using this code:


Is this good, or is there a more efficient way? Cheers

Looks good, except for the creation of the image. That piece of code won't compile. Change it into this instead:


I'll move this thread to our gaming forum.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Andy Joness
Greenhorn

Joined: Sep 15, 2009
Posts: 24
Thanks, I've got full screen working now. The problem I have now is when I change the resolution, the position of the swing components change. I need a way to make sure they stay in a certain position relative to the screen size. BoxLayout seems to automatically do this, however this limits where on the panel I can place things.
Seabook Chen
Greenhorn

Joined: Mar 30, 2011
Posts: 10
Andy Joness wrote:Thanks, I've got full screen working now. The problem I have now is when I change the resolution, the position of the swing components change. I need a way to make sure they stay in a certain position relative to the screen size. BoxLayout seems to automatically do this, however this limits where on the panel I can place things.


You could use WindowToolKit, I can't remember the exact name, just give a google. You got what you need.
Seabook Chen
Greenhorn

Joined: Mar 30, 2011
Posts: 10
I thought it was not a completed answer, so I checked the API.
And you can use the following code to get the screen size. From my experince, gaming needs lots of position calculation. So good luck.

Andy Joness
Greenhorn

Joined: Sep 15, 2009
Posts: 24
I have the interface set up and I've created a settings screen which allows the choice of fullscreen or windowed, and automatically sets the fullscreen resolution to the users' native resolution.

However I'm having real trouble with the layout manager in Netbeans, it's horrible to work with. When I change between 1680x1050 down to 1280x800 the buttons/labels/panels etc move position. If there were a layout which allowed for relative position, like in web design, it would be so much easier. Grid Bag Layout looks promising, however once again Netbeans makes it so much hassle to customise.
Andy Joness
Greenhorn

Joined: Sep 15, 2009
Posts: 24
Edit: Double post
Andy Joness
Greenhorn

Joined: Sep 15, 2009
Posts: 24
I've come up with a clunky way of manually positioning everything so it stays in the same place regardless of resolution or if it's windowed.

I'm sure it's definitely not the best way of doing this, however I despise the layout manager and I need to crack on with things, so it'll do unless anyone can offer some insight on a better method. I've been searching Google for hours with no luck.



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating my first game
 
Similar Threads
Background image for a Swing GUI
Background image not loading on JPanel
Painting an image on a button
Painting components over images
avoiding flickering