123456789101112131415161718192021222324 |
- export default class NodeUtils
- {
- /**
- * 获取节点全局坐标
- * @param node
- * @param out
- */
- public static GetNodePos(node:cc.Node,out:{x:number,y:number}):void{
- let nodePos:cc.Vec3=new cc.Vec3();
- let parentPos:cc.Vec3=new cc.Vec3();
- let anchorPoint:cc.Vec2=node.getAnchorPoint();
- let nodeSize:cc.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;
- }
- }
|