@blinkk/degu
    Preparing search index...

    Function calculateCenterOffset

    • Calculates the offset value to center a given element within a container.

      Imagine the below:

      ------------------8 (parent)----------------
      | |
      | |----5(child)-----| |
      | |
      |---offset--| |
      --------------------------------------------

      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.

       let x = mathf.calculateCenterOffset(
      screen.width, object.width);
      let y = mathf.calculateCenterOffset(
      screen.height, object.width);

      Parameters

      • parent: number

        The parent value

      • child: number

        The child value

      Returns number

      The offset value.