Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (524)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
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] [solved] Nested Tables Rendering incorrectly  (Read 451 times)
0 Members and 1 Guest are viewing this topic.
Offline Grama

Junior Newbie





« Posted 2014-05-09 17:07:21 »

I am attempting to learn the basics of LibGDX by creating a few simple board games. I want to create a basic chess board, and to do so, I am using scene2d and tables. Basically, what I have is a class
1  
GridSceneBoard
that extends
1  
Table
.

The problem I am having is that I want to nest the board into another table. I do so with the following code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
public void show() {
    width       = Gdx.graphics.getWidth();
    height      = Gdx.graphics.getHeight();
    viewport    = new FitViewport(STAGE_WIDTH, STAGE_HEIGHT);
    stage       = new Stage(viewport);
    sceneBoard  = new GridSceneBoard(10, 30, GridBoardCell.Type.CHECKERED);
    rootTable   = new Table();

    rootTable.setFillParent(true);
    sceneBoard.setFillParent(true);

    rootTable.add(sceneBoard);

    stage.addActor(rootTable);
    Gdx.input.setInputProcessor(stage);
}


Both the board and the rootTable have setFillParent set to true. If I directly add the board to the stage, it appears centred on the screen, as I expect.

The render code is as follows:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
public void render(float delta) {
    // Set black background.
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    // Uncomment for table lines during debugging.
    rootTable.debug();
    sceneBoard.debug();
    Table.drawDebug(stage);

    stage.act(Gdx.graphics.getDeltaTime());
    stage.draw();
}


The result is:


Any suggestions as to what I am doing wrong?
Offline Grama

Junior Newbie





« Reply #1 - Posted 2014-05-12 17:38:38 »

Bump. No love? Does it help if I say that the board is a table of images? :S
Offline Nate

« JGO Bitwise Duke »


Medals: 158
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #2 - Posted 2014-05-12 19:45:00 »

https://github.com/libgdx/libgdx/wiki/Scene2d.ui#stage-setup
Quote
Normally a widget's size is set by its parent and setFillParent must not be used. setFillParent is for convenience only when the widget's parent does not set the size of its children (such as the stage).

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline atombrot
« Reply #3 - Posted 2014-05-12 19:47:56 »

Can you show the code of your GridSceneBoard. It's hard to say without knowing how the scene is created.

Try to remove the setFillParent call on the game board. I'm not sure if it was just me beeing dumb, but I didn't get it to work like that. I only use the setFillParent method on the root table.

Change your add line to this:
1  
rootTable.add(sceneBoard).fill().expand();


The root table will do the layouting for the child table.

Make sure you check out the tutorial on the table layout github page: https://github.com/EsotericSoftware/tablelayout
Offline Grama

Junior Newbie





« Reply #4 - Posted 2014-05-12 22:40:37 »

I had checked this, but apparently had set it in the GridSceneBoard's constructor as well. Stupid mistake on my part.

Anyways, its solved now, thanks. Smiley
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.

toopeicgaming1999 (16 views)
2014-11-26 15:22:04

toopeicgaming1999 (15 views)
2014-11-26 15:20:36

toopeicgaming1999 (7 views)
2014-11-26 15:20:08

SHC (24 views)
2014-11-25 12:00:59

SHC (24 views)
2014-11-25 11:53:45

Norakomi (24 views)
2014-11-25 11:26:43

Gibbo3771 (22 views)
2014-11-24 19:59:16

trollwarrior1 (36 views)
2014-11-22 12:13:56

xFryIx (74 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50
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!