美文网首页
Cocos坐标转换笔记

Cocos坐标转换笔记

作者: 浪荡少年 | 来源:发表于2021-01-04 13:55 被阅读0次

得到屏幕坐标:单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);

相关文章

网友评论

      本文标题:Cocos坐标转换笔记

      本文链接:https://www.haomeiwen.com/subject/ycqvoktx.html