Hi,
target3.getComponent(cc.Widget).top = 97;
The above line sets the value in pixels.
Is there any way to set this value in percentage via code.
Thanks,
Hi,
target3.getComponent(cc.Widget).top = 97;
The above line sets the value in pixels.
Is there any way to set this value in percentage via code.
Thanks,
I haven’t tried this myself but have you tried using a string ?
.top = '97%'
I am quite sure this didn’t work , i remember tried doing this way earlier.
Besides in api it specifies the type as Number.
You’re right. I just tried it myself and couldn’t find a way to do it.
From the documentation on class cc.Widget:
- isAbsoluteHorizontalCenter Boolean If true, horizontalCenter is pixel margin, otherwise is percentage (0 - 1) margin.
- isAbsoluteVerticalCenter Boolean If true, verticalCenter is pixel margin, otherwise is percentage (0 - 1) margin.
- isAbsoluteTop Boolean If true, top is pixel margin, otherwise is percentage (0 - 1) margin relative to the parent’s height.
- isAbsoluteBottom Boolean If true, bottom is pixel margin, otherwise is percentage (0 - 1) margin relative to the parent’s height.
- isAbsoluteLeft Boolean If true, left is pixel margin, otherwise is percentage (0 - 1) margin relative to the parent’s width.
- isAbsoluteRight Boolean If true, right is pixel margin, otherwise is percentage (0 - 1) margin relative to the parent’s width.
Seems that this is what you need.