java - Positioning a WidgetGroup in LibGDX -
i'm using horizontalgroup in libgdx works fine. want create row of tiles. when seek position grouping using setposition() method, doesn't position hope, say, doesn't render using "y" value. here code:
a = new tile(missingwords.getam().get("a2.png", texture.class), "a", 3); b = new tile(missingwords.getam().get("a2.png", texture.class), "a", 3); c = new tile(missingwords.getam().get("a2.png", texture.class), "a", 3); a.setsize(50, 50); b.setsize(50, 50); c.setsize(50, 50); submitgroup = new horizontalgroup(); submitgroup.addactor(a); submitgroup.addactor(b); submitgroup.addactor(c); submitgroup.setposition((gdx.graphics.getwidth() - submitgroup.getminwidth()) / 2, 0); stage.addactor(submitgroup); here tile code:
public class tile extends actor { private string letter; private int points; private texture texture; public tile(texture tiletexture, string letter, int points) { this.letter = letter; this.points = points; texture = tiletexture; } @override public void draw(batch batch, float parentalpha) { batch.draw(texture, getx(), gety(), getwidth(), getheight()); } as can see, use:
submitgroup.setposition((gdx.graphics.getwidth() - submitgroup.getminwidth()) / 2, 0); this means should render @ y = 0. however, take @ screenshot:
the tiles out of screen , don't know why. missing?
thanks in advance.
looks reason default alignment in horizontalgroup: align.center. because of tile y positions -25.0 (which tile actor's height / 2). illustration if create tile height of 100 y position of tile in horizontalgroup -50.
i see 2 ways of positioning tiles want it:
fixing alignment of horizontalgroup bottom:submitgroup.align(align.bottom); by setting y position of horizontalgroup 25 instead of 0; java widget libgdx scene2d
No comments:
Post a Comment