Full Screen & Splash Screens

I'm using the full screen API, and I've run into some problems... I'd like to have my game load, and have some sort of image along with spots you click for "Start Game", "Quit Game", etc. My first thought was, have a panel in my full screen frame that holds that, and when the user clicks "Start Game", remove the panel from the full screen frame and add the drawing Canvas of the game instead. This, for some reason, results in my game having absolutely miserable performance... I second-long jumps between frames and points and that sort of thing. So, how can I do this better?

[589 byte] By [cbisbee] at [2007-9-27 20:18:06]
# 1

First of all, you gotta understand what a Panel is. No matter you are using Swing or AWT, panel can be the bottom most part which contains many containers on top of itself. So you can create a base panel which contains your main menu panel, and there is an animation panel which is loaded but invisible at first. Then when the users click start, it will make your main menu panel invisible and make your animation panel visible. If you want more performance, you can even unload(.enabled = false) and call a garbage collection before loading the game.

Hope this help.

hksdu2k at 2007-7-7 0:35:48 > top of Java-index,Other Topics,Java Game Development...
# 2

I may not be that experienced with Java, or the AWT for that matter, but I have a good enough understanding to know how Containers work... But just to make sure, I tried replacing my GridLayout with a FlowLayout and using setVisible and setEnabled... And it's even worse than my using remove()/add().

cbisbee at 2007-7-7 0:35:48 > top of Java-index,Other Topics,Java Game Development...
# 3

In a pathetic attempt to get someone to answer my question, I'm adding Duke Dollars and bumping the question up the list.

I've got a little further info too... I have two Panels... Call them the GamePanel and the StartGamePanel. When you press the button on the StartGamePanel, it should make the SGP invisible and the GamePanel visible. It does, but the problem once again is that the graphics get very jerky. However, if you create the StartGamePanel and never set it visible (just tell it to create the GamePanel during StartGamePanel creation), everything is ok.

Any ideas? Or is there anything else I could provide to help get an answer?

cbisbee at 2007-7-7 0:35:48 > top of Java-index,Other Topics,Java Game Development...
# 4

Hey, i'll just plug my own game!

When the app starts i create a new GameFrame which extends JFrame, and a GameDialog which extends JDialog, funnily enough.

The GameDialog has buttons for new game,options,etc.

Then when the users hits the start button, it calls GameFrame.startGame(), or if already running GameFrame.resume().

The GameFrame.startGame() calls initDisplay(), initOffScreen, running = true, and starts the thread.

initDisplay() just calls some JFrame settings like setSize(), setVisible(),etc.

initOffScreen() creates the back buffer VolatileImage.

Have a look at http://java.sun.com/docs/books/tutorial/extra/fullscreen/

That explains how you use VolatileImages correctly, more care is needed than using normal Images. I suspect thats where your getting performace problems.

Also you can call createImage(w,h) and it will create a non-volatile image, but attempt to hardware accelerate as much as possible, which takes alot of the hassel out of using VolatileImages.

Even simpiler you can use BufferStrategy, which is designed around use in a game type main loop. From my experiance creating the VolatileImage myself was the fastest, but its probally not always the case, and the design is much cleaner using BufferStrategy.

Hope that helps!

Harley.

my games a yat spaceshooter, just crappy art!

harleyrana at 2007-7-7 0:35:48 > top of Java-index,Other Topics,Java Game Development...
# 5

I noticed you are using two panels, for the game and splash screen.

Thats not the best way to go, because you have to add/remove each. Instead make each a top level container, like Frames, Dialogs,etc.

That way each component is only painting itself, and you don't need to use layouts or add/remove.

from the last post id suggest using BufferedStategy, because it simplifys heaps.

Im happy to answer any other questions.

Harley.

harleyrana at 2007-7-7 0:35:48 > top of Java-index,Other Topics,Java Game Development...
# 6

Sorry for the confusion, but I guess I really need to learn how to express my exact problems better.

1) I DO have a Frame containing both panels(you kind of have to have a Window of some sort for FullScreen, don't you?), and I am now using the setVisible() technique to determine which is showing.

2) I already use the createImage() method to make my images... VolatileImages were causing all kinds of problems for me (prolly cuz I wasn't using them correctly) and generic Images have been adequate... So I haven't dealt with VIs.

I'll try BufferStrategy again, though I've had a tough time getting that to work. I kept getting some sort of "needs a Peer" error every time I tried to use it before, so I went back to manually double buffering.

Thanks for the suggestions though...

cbisbee at 2007-7-7 0:35:48 > top of Java-index,Other Topics,Java Game Development...
# 7

If anyone really wants to dig into it... You can download:

http://c3po.lpl.arizona.edu/~biz/pirates/Pirates-fast.jar

and

http://c3po.lpl.arizona.edu/~biz/pirates/Pirates-slow.jar

The fast and slow jars are virtually the same thing... Slow just includes the extra StarterPanel, while fast "jumps starts" the game by not creating the StarterPanel and instead immediately starts the GamePanel.

A couple of other notes:

1) No, I haven't digitally signed any of this... Honestly, I don't really see the point. I'm not going to shell out the cash to get a real certificate, and I don't have a clue why you would trust a certificate I generated myself.

2) There's a bug in the code I haven't gotten around to fixing yet... (Test week at school) It involves when you change map sections because of a mix of the water and wind currents. I'm pretty sure I know what to do... I just haven't fixed it.

3) I apologize in advance for what I'm sure is sloppy code. I've been teaching myself Java with the help of a friend from my old college days, and just went back to school this fall. Bottom line is, I have VERY little formal programming training and I'm sure my code is pretty poor compared to those who've been through school.

4) The classes of interest SHOULD be:

Pirates, PiratesGameStarter, and GameStarterPanel, which are all in the bisbee.pirates branch of the jar. (source IS included)

P. S. Harley, where's your game at? Didn't see a link...

cbisbee at 2007-7-7 0:35:48 > top of Java-index,Other Topics,Java Game Development...