LibGDX - Issue with Scene2D Dialog

Hi guys,

I’ve just been messing around with my dialog code and found out that I can centre it by using

dialogInstance.show(stage)

Though when I tried this… it doesn’t display! I’m having to manually add it to the stage and then it’s not centred :frowning:

Any ideas what it could be?

Just center it yourself, probably in your dialog’s constructor:

setPosition((Gdx.graphics.getWidth() - getWidth()) / 2f,(Gdx.graphics.getHeight() - getHeight()) / 2f);

I prefer to use “add” to stage to control widgets’ drawing order, then center them in the constructors. Of course if you’re in a platform where height and width may vary, put the center code in show() instead.

I was hoping I wouldn’t have to do this, I hate doing stuff the long way :stuck_out_tongue:

What do you mean by “long way”? It’s one line in the constructor :slight_smile: