Ngui Study Notes (iii): Screen adaptive

Source: Internet
Author: User

When we develop mobile games, it is common to choose the constrained/fixedsize zoom mode to ensure that the image is consistent with the size of the screen at different resolutions, but it is not enough for screen adaptation. Different phones have different aspect ratios, so we need to introduce the concept of relative position.

As a mature UI plugin, Ngui provides us with a proven screen-adaptive technology.

Anchor components

We can create a anchor component to the stage, the anchor is the anchor point, it can be designated as the camera's 9 points (respectively: top left, top, right, left, middle, right, bottom left, bottom and bottom right) for its anchor point, when the size of the camera changes (that is, the screen size changes), The anchor component can correct its current position, and the component's relative positioning is achieved by dragging components that need relative positioning into the stroke component.

A few things to note:

    1. The Runonlyonce property, which determines whether the game window size will not change during the run of the mobile game, so it can be checked if it is only applied at the beginning.
    2. Anchor components do not need to be dragged manually.

Pivot Properties for Components

That is, the center point of the component or the registration point, the rotation offset of the component depends on that point and can be considered as the local origin of the component.

Component's Anchors Property

Unlike the anchor component, the anchors property is a relatively positioned property that is provided by all the underlying components.

The effect is to have the position and dimensions of the current component relative to another component, and if the target component changes, these changes will affect the relative component.

The anchors property can set the relative component that is the position of the four sides of the component.

Ngui Study Notes (iii): Screen adaptive

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.