UI element anchor

Is there any equivalent of an element anchor in CC, like in Godot for example?


I want to hang it on a button so that when the window size changes, it does not move, but remains in place.
How it is now:


It should be:

I think Widget component should help you with this:
https://docs.cocos.com/creator/manual/en/ui-system/components/editor/widget.html?h=widget

Thank you, but unfortunately the widget did not help, so I still had to solve the problem with code. For fit width:

code option for the button:

    pos_y: number = null;

    //
    protected onLoad(): void {
        let design_resolution = view.getDesignResolutionSize();
        this.pos_y = this.node.position.y * (design_resolution.x / design_resolution.y);
        this.new_position();
        screen.on("window-resize", this.new_position);
    }

    //
    protected onDestroy(): void {
        screen.off("window-resize", this.new_position);
    }

    new_position = (): void => {
        let screen_resolution = screen.resolution;
        this.node.setPosition(this.node.position.x, this.pos_y / (screen_resolution.x / screen_resolution.y));
    }
1 Like