12345678910111213141516171819202122232425262728 |
- import { Node, Size, Vec2, Vec3 } from "cc";
- export default class NodeUtils
- {
- /**
- * 获取节点全局坐标
- * @param node
- * @param out
- */
- public static GetNodePos(node:Node,out:{x:number,y:number}):void{
- let nodePos:Vec3=new Vec3();
- let parentPos:Vec3=new Vec3();
- let anchorPoint:Vec2=new Vec2();
- node.getAnchorPoint(anchorPoint);
- let nodeSize:Size=node.getContentSize();
- while(node){
- node.getPosition(parentPos);
- nodePos.x+=parentPos.x;
- nodePos.y+=parentPos.y;
- node=node.parent;
- }
- out.x=nodePos.x-anchorPoint.x*nodeSize.width;
- out.y=nodePos.y-anchorPoint.y*nodeSize.height;
- }
- }
|