Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
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  
  Creating good game UI  (Read 893 times)
0 Members and 1 Guest are viewing this topic.
Offline AppleSauce
« Posted 2014-06-14 19:47:40 »

many rpg type of games have nice UIs that benefit the player through out the game; Usually with a drag and drop functionality. Before I try dabbling with it myself, what would be the most effective way to create UIs like this?


I was thinking of making them dragable by setting its velocity to the mouses' velocity when clicked and have the items in the drop slots keep its' coordinates based off of where the UI box is dragged. I drew an example:


I forgot what you call fake code that's used for an example, but hope this clears the point.

Another idea I had was to use undecorated JFrames instead of an Image UI so the player can move it out of the screen. I could then give that frame a nice UI layout and use the Java API to for the dragging and dropping.
Offline trollwarrior1
« Reply #1 - Posted 2014-06-14 19:56:49 »

Can you please make your example image work?
Offline AppleSauce
« Reply #2 - Posted 2014-06-14 20:05:55 »

My bad, I'll get that fixed right away
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ipe369
« Reply #3 - Posted 2014-06-14 20:15:16 »

Oh, I've seen that UI before. It does look very nice.

I wouldn't bother with setting velocities, seems a bit messy. Just detect when the mouse is pressed onto the object, then get the offset of the mouse. For example:
Say the mouse was pressed at (10,20) on the object. Every loop until the mouse is released, set the item's x position to be mousePosition.x - 10 and the item's y position to be mousePosition.y - 20.
Offline Bearded Cow
« Reply #4 - Posted 2014-06-14 20:18:02 »

I agree with ipe369, don't both with the whole velocity thing, just set its location to the mouse's based on a boolean for 'grabbed' or something.
Offline AppleSauce
« Reply #5 - Posted 2014-06-14 20:19:03 »

I haven't seen any mouse release methods in lwjgl. How would I go about this, yet keeping things simple?
Offline Bearded Cow
« Reply #6 - Posted 2014-06-14 20:22:28 »

I haven't seen any mouse release methods in lwjgl. How would I go about this, yet keeping things simple?

If(!Mouse.isPressed(0))

Release.
Offline AppleSauce
« Reply #7 - Posted 2014-06-14 20:24:27 »

I haven't seen any mouse release methods in lwjgl. How would I go about this, yet keeping things simple?

If(!Mouse.isPressed(0))

Release.

Thanks, I feel like an idiot.  Tongue
Offline trollwarrior1
« Reply #8 - Posted 2014-06-14 20:29:01 »

This is how I would do it.

Create a List of rectangles. These rectangles should represent places where you can pick up, drag or drop items.

User presses down left mouse button -> Check if mouse is colliding with any of the rectangles -> If not, don't do anything. If there is a rectangle that collides, set DraggedItem to the item that rectangle contains -> When mouse is released, check if mouse is colliding with any of the rectangles. If it is, that means that player dragged an item from DraggedItem to currently colliding rectangle.
Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Reply #9 - Posted 2014-06-14 22:02:48 »

Check what some the UI libraries do! Swing, scene2d.ui, TWL, nifty, you name it. They are open source Smiley For drag and drop functionality, check out scene2d.ui's DragAndDrop class, as well as Target.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline loom_weaver

JGO Coder


Medals: 17



« Reply #10 - Posted 2014-06-14 22:29:51 »

I haven't seen any mouse release methods in lwjgl. How would I go about this, yet keeping things simple?

Just go into it knowing that it's not going to be simple.  I have great appreciation for the developers who have written major UI libraries.

Abstracting raw mouse/key events into an event dispatch system is tricky especially when you consider drag/drop, focus, window z-stack, and modal.

_If_ you want want to write things from scratch count on spending at least a month full time to get something useable and definitely not complete.  This is considering you are working off the shoulders of giants e.g. looking at how awt, TWL, nifty, etc. are implemented.

You will have to start with a UIComponent that stores a location + dimension, can paint itself, have children, and can handle events.

I've probably spent between 30-45 days on mine.  I think it's worth it in the long run - good learning experience and I have a framework that avoids spaghetti code.  If you don't want to spend that time e.g. would rather write your game then your only option is to learn a library.

Good luck.
Offline AppleSauce
« Reply #11 - Posted 2014-06-14 22:55:10 »

Thanks  Cheesy I'm guessing spaghetti code is sloppy unorganized code. I just edited this image. (I don't know how to scale this crap)
Offline Jacob Pickens
« Reply #12 - Posted 2014-06-15 04:10:56 »

Thanks  Cheesy I'm guessing spaghetti code is sloppy unorganized code. I just edited this image. (I don't know how to scale this crap)


The funny message in the picture is in there somewhere haha
Pages: [1]
  ignore  |  Print  
 
 

 

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

The first screenshot will be displayed as a thumbnail.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (43 views)
2014-10-16 15:22:06

Norakomi (33 views)
2014-10-16 15:20:20

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (67 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (86 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!