Logical position of click, relative to sprite

Hello there. My first time with Cocos (Cocos Creator). Web.
I have a sprite and I want to know a logical coord (0…1) of the click at it.
At the moment I calculate it through UITransform:

    onPressed(event: EventTouch) {
        let ui = event.target.getComponent("cc.UITransform") as UITransform;
        let pos = event.getLocation();
        let relative_pos = ui?.convertToNodeSpaceAR(new Vec3(pos.x, pos.y, 0));
        ...

It works fine when game started from IDE. But it breaks if you click to change orientation (Rotate button). Also it breaks when the game is started as web build.

How can I handle it?

Found the problem. Should be used getUILocation() instead of getLocation()

1 Like