How can you universally calculate the screen center for any device?

0 favourites
  • 3 posts
From the Asset Store
A futuristic device, can be used as radarscreen, optionscreen, infodisplay, research device, ...
  • Is there a universal way to find the center of the screen, e.g. horizontally to display a button?

    There is a button with options:

    Button.width = 400;

    Button.height = 50;

    Origin = Top-left;

    So when using this formula, the button is not always displayed in the center:

    Button.X = PlatformInfo.CanvasDeviceWidth / 2 - Button.Width / 2

    how to determine the center of the screen of any device?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Use the system viewport expressions to identify the middle of the visible area taking in to account scrolling, scale etc. You must pass a layer to take in to account the layer transform. (ViewportLeft("Layer 0") + ViewportRight("Layer 0")) / 2 will the X co-ordinate of the middle of the screen for "Layer 0", and (ViewportTop("Layer 0") + ViewportBottom("Layer 0")) / 2 the Y co-ordinate.

  • Use the system viewport expressions to identify the middle of the visible area taking in to account scrolling, scale etc. You must pass a layer to take in to account the layer transform. (ViewportLeft("Layer 0") + ViewportRight("Layer 0")) / 2 will the X co-ordinate of the middle of the screen for "Layer 0", and (ViewportTop("Layer 0") + ViewportBottom("Layer 0")) / 2 the Y co-ordinate.

    Thanks, you've been very helpful.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)