Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (481)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (548)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Rendering and hiding grouped text in a final fantasy battle screen  (Read 1232 times)
0 Members and 1 Guest are viewing this topic.
Offline Tennie

Senior Newbie





« Posted 2007-04-05 16:52:44 »

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?

Some people become relaxed and/or feel at peace with themselves/the universe because they smoke, pray, or meditate. Me, I code.
Offline Kova

Senior Member





« Reply #1 - Posted 2007-04-05 19:45:34 »

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...
Offline Tennie

Senior Newbie





« Reply #2 - Posted 2007-04-05 20:47:18 »

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:


Some people become relaxed and/or feel at peace with themselves/the universe because they smoke, pray, or meditate. Me, I code.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Kova

Senior Member





« Reply #3 - Posted 2007-04-05 21:45:32 »

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.

Offline Tennie

Senior Newbie





« Reply #4 - Posted 2007-04-05 22:47:52 »

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 Smiley

 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?

Some people become relaxed and/or feel at peace with themselves/the universe because they smoke, pray, or meditate. Me, I code.
Offline Kova

Senior Member





« Reply #5 - Posted 2007-04-06 01:35:17 »

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.
Offline Tennie

Senior Newbie





« Reply #6 - Posted 2007-04-06 02:30:02 »

ok thanks

Some people become relaxed and/or feel at peace with themselves/the universe because they smoke, pray, or meditate. Me, I code.
Offline fletchergames

Senior Member





« Reply #7 - Posted 2007-04-06 14:48:57 »

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.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (26 views)
2014-08-19 09:29:53

Tekkerue (24 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (14 views)
2014-08-16 06:20:21

Tekkerue (21 views)
2014-08-16 06:12:11

Rayexar (59 views)
2014-08-11 02:49:23

BurntPizza (38 views)
2014-08-09 21:09:32

BurntPizza (30 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!