Rendering and hiding grouped text in a final fantasy battle screen

Hey guys, I was wondering if anyone knows the best way (or rather, your way) to display a few options with a cursor.

Basically, during most battles in a final fantasy type of game, each character has 4 basic options: Attack, Use Skill, Use Magic, Use Item.

Since each character has different skills though, the thing that contains the text and the cursor must appear for each character, then disappear right after the user has selected the option he wants.

How would you do that?

I’m not sure if I understood correctly… when you move cursor on some character you want for a small menu to appear close to the cursor, and when something is selected you want it to disappear?
Note that I have never used mouse cursor for drawing or have ever changed mouse cursor, but this is how I would try to do it.
Well you do that like everything else… you draw stuff under conditions. You get mouse position every time, and when it’s on some character than you draw a menu, for example, above the cursor position. You keep drawing it until something from menu is selected or mouse position is over some other character or some time has passed or whatever else has happened…

you’ve got the idea of the battle situation. Except the text and the cursor would appear down below, not next to the character, and the cursor would be controlled by the keyboard, not the mouse, but those are trivial details.

Kova, how would you organize the text ? I’m hoping for a more technical answer, because I don’t have too much experience with programming graphics in java. for example, would you place each option into its own JButton with a corresponding Action, then put those JButtons onto a JPanel, and when it is time for the options to be displayed would you overlay that jpanel on top of the battle screen’s jpanel, and then hide the jpanel with the buttons once that player’s turn is over?

I’m inserting an image to show an example of a typical battle screen:

U wouldn’t use Swing at all… it’s huge pain in the ass, I’ve tried… For example, as soon as you click some option on the menu, swing component will steal the focus and your game will be unresponsive to keyboard commands, you need to worry to give back focus at the end of every communication with the swing menu … and much more.

Although I haven’t ever built a passive rendering swing game, your idea of laying out components sounds fine. It’s like you are building a normal application, just that data for menu to show changes very often.
I’m not sure what do you mean with “overlay that jpanel on top of battle screen’s jpanel” … I would just try to use normal approach, add menu panel to battle screen panel and show / hide it when needed (hmm, can you do that? it’s been a while since I worked with swing, if component is added and then hidden, is it’s area empty, seethrough?). If that cannot be done then remove / add component every time.

lol alright will do. thanks a ton.

what I meant by that statement is exactly what you called the normal approach. Sorry I was confusing.

Thanks again, you’ve cleared up that design issue for me :slight_smile:

P. S. I agree with what you said about Swing, but I don’t know what else to use in java. Do you suggest switching to one of the open GL libraries? or is there another way to do graphics that I haven’t mentioned?

nah, OpenGL is overkill for such simple 2D games… I was thinking more of using images for everything. Not very dynamic if you want to change layout of menu but still it’s much simpler to code.

ok thanks

Since the menu items don’t get clicked on, they’re just text. The cursor is seperate. For the text, use JLabels in Swing or just draw it directly to the Graphics object.

You can make the menu JPanel a JDialog instead. If you make it modal, it should take and keep the focus, preventing the player’s keyboard input from getting captured by any other part of the interface. For drawing the text directly, you would extend the JDialog class and override the paintComponent method.

For changing the text, you can just change the text of the JLabels (I believe the correct method is called “setText”) or just change what text you’re drawing (if you’re drawing the text yourself).

You can use images if you want, but that’s not really any better than drawing the text directly.

If you like, you can avoid using Swing Components altogether and just draw the whole screen. You’ll need some kind of Frame (from Awt) or JFrame (from Swing), but you can draw everything youself.

I like using Swing just because it gives me a bunch of components to use.