3
\$\begingroup\$

Is it somehow possible to set Scene2D table cell´s size in percentage of the table?

I would like to have orientation independent menu, with buttons filling let´s say 75% percent of the screen, and also to respond on window resizing (desktop version). I have tried several methods, for example using Value

table.add(button).width(Value.percentWidth(.75F));

but when value.get(actor) is called inside cell, it is supplied with inner button actor not its container (table).

I have also tried to set it in fixed fashion

table.add(button).width(Value.percentWidth(.75F).get(table));

This works fine, but since I set pixel value insted of Value object it is not recalculated upon resizing.

Is there any way to achieve this?

\$\endgroup\$
3
\$\begingroup\$

You can change the Actor that the Value acts on by supplying the actor (in your case your table) in the constructor like so:

table.add(button).width(Value.percentWidth(.75F, table));

This will make Value use that actor for the Value#get(actor) method instead of the default parent actor.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.