Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (761)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (845)
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  
  Scene2D UI - make grid  (Read 2272 times)
0 Members and 1 Guest are viewing this topic.
Offline israelg99
« Posted 2014-02-04 17:11:51 »

Hello, i am trying to make an inventory for my game, and for that i need to make a grid.
I am trying to get this done with the table -

1  
2  
3  
table = new Table();
table.setFillParent(true);
stage.addActor(table);


Where should i go from here?
I want my grid / inventory to look similar to this -

Offline Gibbo3771

JGO Kernel


Medals: 128
Projects: 5
Exp: 1 year


Currently inactive on forums :(


« Reply #1 - Posted 2014-02-04 17:30:03 »

Funny enough this is actually already done, when you create a table it has empty cells. All you would need to do is set a fixed table size, say 200x200px, you could fit 10 actors in each row if they are 20px each, once it gets to the end it starts on a new collumn.

All you would need to do is occupy the table with xx amount of placeholder actor, like have a class called EmptySlot.

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Offline israelg99
« Reply #2 - Posted 2014-02-05 11:23:50 »

Funny enough this is actually already done, when you create a table it has empty cells. All you would need to do is set a fixed table size, say 200x200px, you could fit 10 actors in each row if they are 20px each, once it gets to the end it starts on a new collumn.

All you would need to do is occupy the table with xx amount of placeholder actor, like have a class called EmptySlot.
There is a way to fill the table without using loop or to hardcode everything?
Just something like this -
1  
table.fill(howManyCells, cellSize)

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

JGO Knight


Medals: 28
Projects: 3
Exp: 5 years


https://github.com/wreed12345


« Reply #3 - Posted 2014-02-05 12:08:12 »

I am not aware of anything like that... I think you would be best off creating your own method that takes in your desired parameters and handles mass creation of some actor.

Offline trollwarrior1
« Reply #4 - Posted 2014-02-05 12:25:03 »

Why don't you just make your own grid? Cheesy

I bet Notch made those "grids" himself.
Offline wreed12345

JGO Knight


Medals: 28
Projects: 3
Exp: 5 years


https://github.com/wreed12345


« Reply #5 - Posted 2014-02-05 12:28:11 »

I really don't like the look of all those static methods.... I too once went down that path as i began game dev over a year ago I have come so much since then. Don't let this happen to yourself

Offline BurntPizza

« JGO Bitwise Duke »


Medals: 485
Exp: 7 years



« Reply #6 - Posted 2014-02-06 02:45:00 »

Everything you could want to know about Table <-- This is the same Table that is in scene2d ui

Quick take at a fill() method:
1  
2  
3  
4  
5  
6  
7  
public void fill(Table t, Image blankSlot, int columns, int rows) {
      for(int r = 0; r < rows ; r++) {
            for(int c = 0; c < columns; c++)
                  table.add(blankSlot).pad(2);
            table.row();
      {
}


Take a good look through those docs, they're good.
Offline israelg99
« Reply #7 - Posted 2014-02-07 16:20:07 »

Why don't you just make your own grid? Cheesy

I bet Notch made those "grids" himself.
I forgot to update you guys, but i used his idea to create my grid for the inventory. and it goes pretty nice.
the only downside is that the code is really dirty, and there are too much data to calculate, but its nothing that some "clean ups" won't fix.

Thanks Wink

Offline wreed12345

JGO Knight


Medals: 28
Projects: 3
Exp: 5 years


https://github.com/wreed12345


« Reply #8 - Posted 2014-02-07 21:06:24 »

If you don't mind share the code, I am sure someone in the future who looks at the post would appreciate it

Pages: [1]
  ignore  |  Print  
 
 

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

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

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

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

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

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

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

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

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

Solater (413 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!