Mouse Position To World Position Not Working

Hey, i’m trying to get an finger position

    protected onLoad(): void {
        this.node.on(NodeEventType.TOUCH_START, this.touchedScreen, this);
    }

    protected onDestroy(): void {
        
        this.node.off(NodeEventType.TOUCH_START, this.touchedScreen, this);
    }

    touchedScreen(nodeEvent: EventTouch) {
        if(this.isTouchScreenEnabled)
        {
            this.node.emit("input_event", nodeEvent); 
        }
    }

Like the code below and i want to set something on screen my UI with this function

  showTutorialFinger(targetPosition) {
        var uiTransform = this.fingerSprite.node.parent.getComponent(UITransform);

        var worldPosition = worldPosition = uiTransform.convertToWorldSpaceAR(targetPosition);
        this.fingerSprite.node.setPosition(worldPosition);
    }

but it doesn’t appear on the position i intended. It goes out of screen etc.

this.fingerSprite.node.setPosition(worldPosition) doesn’t seem to make sense.
The param of node.setPosition() should be a localPosition.

Perhaps this what you want

        this.node.on(Input.EventType.TOUCH_START, (e: EventTouch)=>{

            let fingerPos = e.getUILocation();

            fingerNode.setWorldPosition(v3(fingerPos.x, fingerPos.y));

        }, this);

I did and it worked thanks.

I’m trying to make an data that holding some positions on screen so when i saved the UILocation it only works for that particularly UI Resolution.

So i tried to get % percentage of screen by doing that i can find position for each resolution but…

let screenSize = view.getFrameSize();

Outcomes video size : (375.00, 667.00) but UILocation is higher than 667. It’s 1700+ also my design resolution is 1350. And also i’m working with transparent canvas. So how i can manage to calculate position with one position for every resolution ?

Maybe you can directly get the size of Canvas.

@zzy thank you for your help.

let canvasSize = view.getCanvasSize();

only returns 375, 667.
its same as the getFrameSize();

But when i click on top of the screen my getUILocation returns more than 1600+

image

How about this?

let canvasSize = find("/Canvas").getComponent(UITransform).contentSize;

Thanks mate its works again.