1、世界坐标转成模型坐标
--Node1 local node1 = cc.Sprite:create("res/common/node1.png") node1:setAnchorPoint(cc.p(1.0,1.0)) node1:setPosition(cc.p(400,500)) self.panel.layer:addChild(node1) --Node2 local node2 = cc.Sprite:create("res/common/node2.png") node2:setAnchorPoint(cc.p(0.5,0.5)) node2:setPosition(cc.p(200,300)) self.panel.layer:addChild(node2) local x,y = node2:getPosition() local pt1 = node1:convertToNodeSpace(cc.p(x,y)) local pt2 = node1:convertToNodeSpaceAR(cc.p(x,y)) cclog("Node2 NodeSpace = (%f,%f)",pt1.x,pt1.y) cclog("Node2 NodeSpaceAR = (%f,pt2.x,pt2.y)
例图:
打印:
2、模型坐标转成世界坐标
--Node1 local node1 = cc.Sprite:create("res/common/node3.png") node1:setAnchorPoint(cc.p(0.5,0.5)) node1:setPosition(cc.p(400,500)) self.panel.layer:addChild(node1) --Node2 local node2 = cc.Sprite:create("res/common/node4.png") node2:setAnchorPoint(cc.p(0.0,0.0)) node2:setPosition(cc.p(0,0)) node1:addChild(node2) local x,y = node2:getPosition() local pt1 = node1:convertToWorldSpace(cc.p(x,y)) local pt2 = node1:convertToWorldSpaceAR(cc.p(x,y)) cclog("Node2 WorldSpace = (%f,pt1.y) cclog("Node2 WorldSpaceAR = (%f,pt2.y)例图:
打印: