You have a parent of width 8 and child of with 5 and you want to
center the child.
In the example above, parent = 8, child = 5, would return the offset of 1.5
So you know that if you offsetted the child element by 1.5, it would
horizontally center.
You can also use this method to calculate vertical alignment as well.
Example:
Here is an example of calculating the x, y offsets to center an object
to the screen.
letx = mathf.calculateCenterOffset( screen.width, object.width); lety = mathf.calculateCenterOffset( screen.height, object.width);
Calculates the offset value to center a given element within a container.
Imagine the below:
You have a parent of width 8 and child of with 5 and you want to center the child.
In the example above, parent = 8, child = 5, would return the offset of 1.5 So you know that if you offsetted the child element by 1.5, it would horizontally center.
You can also use this method to calculate vertical alignment as well.
Example: Here is an example of calculating the x, y offsets to center an object to the screen.