得到屏幕坐标:单Canvas层
//直接用相机getWorldToScreenPoint
let screenPos = cc.Camera.main.getWorldToScreenPoint(this.node.position);
从世界坐标转屏幕坐标:单UI层
let worldPos = this.node.convertToWorldSpaceAR(cc.v2(0, 0));
let pos = parent.convertToNodeSpaceAR(worldPos);
从场景坐标转屏幕坐标:Scene层下的物品坐标转UI层
let sceneCamarePos = this.SceneCamare.getWorldToCameraPoint(cc.v2(this.node.x, this.node.y));
let screenPos = cc.Canvas.instance.node.convertToNodeSpaceAR(sceneCamarePos);
从屏幕坐标转场景坐标:UI层的点转到Scene层下
let touchPos = event.getLocation();
let worldPos = cc.Camera.main.getScreenToWorldPoint(touchPos);
let sceneCamarePos = cc.find('Scene/SceneCamera').getComponent(cc.Camera).getScreenToWorldPoint(worldPos);
let sceneWorldPos = this.node.parent.convertToNodeSpaceAR(sceneCamarePos);
网友评论