Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (763)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (852)
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  
  LibGDX - Draw inventory in one place (The correct way)  (Read 3026 times)
0 Members and 1 Guest are viewing this topic.
Offline SauronWatchesYou

JGO Ninja


Medals: 33
Projects: 4
Exp: 2 years


Hi there! :)


« Posted 2015-05-27 17:19:58 »

Hi all.

Sorry for the noob question but i'm building my inventory system from scratch. I need to keep the inventory in once place at all times (When the user presses "I").

At the moment i'm making the inventory use its own spritebatch for the rendering as this keeps it in one place, however it is drawn pretty small. The inventory is also drawn in the bottom left but the "contains" method that tells me if the user is hovering over a slot is returning in the top right. Do I also need to give the batch a camera so it flips the inventory to the top of the screen? Or am I missing something Pointing


Hey, you! Back to work
Offline craftm

JGO Coder


Medals: 15
Projects: 1


_Keep Trying


« Reply #1 - Posted 2015-05-27 17:57:08 »

I think it's more easy create an inventory and other interface elements using a Stage and Scene2D. If you are using the same batch (and this batch is projected to the camera matrix and this camera moves) you will have to solve many problems.

The Game: Running on "world virtual coordinates".
Interface: Running on "Screen coordinates".

You can do this using the same batch and camera, but I think you will get more work, including all other elements.

_ Wink
Offline SauronWatchesYou

JGO Ninja


Medals: 33
Projects: 4
Exp: 2 years


Hi there! :)


« Reply #2 - Posted 2015-05-27 18:00:45 »

I think it's more easy create an inventory and other interface elements using a Stage and Scene2D. If you are using the same batch (and this batch is projected to the camera matrix and this camera moves) you will have to solve many problems.

The issue with Scene2D is that it has drag and drop support but it is not good for what I need. I need the player to be able to drag items out of inventory and throw them on the ground and I don't believe this is possible. Sad

Hey, you! Back to work
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline craftm

JGO Coder


Medals: 15
Projects: 1


_Keep Trying


« Reply #3 - Posted 2015-05-27 18:08:24 »

I think it's more easy create an inventory and other interface elements using a Stage and Scene2D. If you are using the same batch (and this batch is projected to the camera matrix and this camera moves) you will have to solve many problems.

The issue with Scene2D is that it has drag and drop support but it is not good for what I need. I need the player to be able to drag items out of inventory and throw them on the ground and I don't believe this is possible. Sad
Yes you can.

I did it in my game: https://play.google.com/store/apps/details?id=com.drawyourway.games.android
You draw horizontal lines in "screen coord" and the line is drawn in game coord.

You can convert (the right word is to project actually) Screen coord --> Game Coord or Game Coord --> Screen Coord using camera.project() or camera.unproject().

So, you can apply this after your drag and drop. In your case, create a new object in the game world (using the new coord).

_ Wink
Offline SauronWatchesYou

JGO Ninja


Medals: 33
Projects: 4
Exp: 2 years


Hi there! :)


« Reply #4 - Posted 2015-05-27 18:24:08 »

I did it in my game:

:O I read online that you couldn't do that due to needing to drop it onto a source. Maybe I can make the array the source and then for every object in the array, draw the items at their coords.

I would do camera.project to get screen to world cords, correct? Smiley

Hey, you! Back to work
Offline craftm

JGO Coder


Medals: 15
Projects: 1


_Keep Trying


« Reply #5 - Posted 2015-05-27 18:32:58 »

I did it in my game:

:O I read online that you couldn't do that due to needing to drop it onto a source. Maybe I can make the array the source and then for every object in the array, draw the items at their coords.

I would do camera.project to get screen to world cords, correct? Smiley
You can't drop the same source object, because the interface it's only an image, but you can get all the information needed to spawn the object in the game.

Screen to World: camera.unproject(Vector3);

Your Vector3 will have the new coord and you can use an ID from the item dropped to know which item need to spawn.
 Cheesy

_ Wink
Offline SauronWatchesYou

JGO Ninja


Medals: 33
Projects: 4
Exp: 2 years


Hi there! :)


« Reply #6 - Posted 2015-05-27 18:44:04 »

Thank you very much for your help! I'll try creating a drop and drop with Scene2D and the Stage instead

Hey, you! Back to work
Offline SauronWatchesYou

JGO Ninja


Medals: 33
Projects: 4
Exp: 2 years


Hi there! :)


« Reply #7 - Posted 2015-05-27 20:31:52 »

Hmm.

I have a table built for my inventory system and each cell is an imagebutton (for the slots) but I have an issue. I can't find out anyway of getting which child from the table was touched so I can begin dragging it.

Also, if I already have image buttons for my table, won't I need to create a new image for every single weapon/potion/armor to change the image on the table? If I simply overlay it then how will I get the information? D:

Hey, you! Back to work
Offline craftm

JGO Coder


Medals: 15
Projects: 1


_Keep Trying


« Reply #8 - Posted 2015-05-28 00:41:15 »

You can implement an interface with all the values you need to your class extending ImageButton (to know/show the info about the iten), I think a Table can be hard to manage drag&drop.
Maybe you can create your own array and grid, and just set a region when you need (in the inventory slot and when is dragged).

Here's an example: http://pixelscientists.com/demos/inventory/index.html
Git: https://github.com/PixelScientists/libgdx-utils

_ Wink
Offline SauronWatchesYou

JGO Ninja


Medals: 33
Projects: 4
Exp: 2 years


Hi there! :)


« Reply #9 - Posted 2015-05-28 01:06:26 »

That's what I was thinking Grin storing info on current item, stack size and max stack inside a class called 'Slot' that extends the imagebutton. Can simply get the info I need that way and shouldn't have to deal with annoying tables Pointing

Hey, you! Back to work
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (541 views)
2018-06-10 19:43:48

EgonOlsen (646 views)
2018-06-10 19:43:44

EgonOlsen (442 views)
2018-06-10 19:43:20

DesertCoockie (788 views)
2018-05-13 18:23:11

nelsongames (1019 views)
2018-04-24 18:15:36

nelsongames (1006 views)
2018-04-24 18:14:32

ivj94 (1587 views)
2018-03-24 14:47:39

ivj94 (560 views)
2018-03-24 14:46:31

ivj94 (1393 views)
2018-03-24 14:43:53

Solater (566 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
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!