Cocos2dx_世界坐标和模型坐标

来源:互联网 发布:ubuntu与fedora的异同 编辑:程序博客网 时间:2024/04/30 01:19

1、世界坐标转成模型坐标

--Node1local 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)--Node2local 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, %f)", pt2.x, pt2.y)

例图:


打印:


2、模型坐标转成世界坐标

--Node1local 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)--Node2local 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, %f)", pt1.x, pt1.y)cclog("Node2 WorldSpaceAR = (%f, %f)", pt2.x, pt2.y)
例图:

打印:



0 0
原创粉丝点击