在cocos2dx中,有四種座標系node
GL座標系:左下爲原點,x軸向右,y軸向上函數
UI座標系:左上爲原點,x軸向右,y軸向下spa
世界座標系:與GL座標系相同code
本地座標系:是節點(CCNode)的座標系,原點在節點左下角,x軸向右,y軸向上事件
GL座標和UI座標轉換在導演類(CCDirector)中it
CCPoint CCDirector::convertToGL(const CCPoint& obPoint); CCPoint CCDirector::convertToUI(const CCPoint& obPoint);
世界座標系和本地座標系轉換在節點類(CCNode)中io
CCPoint CCNode::convertToNodeSpace(const CCPoint& worldPoint); CCPoint CCNode::convertToWorldSpace(const CCPoint& nodePoint); CCPoint CCNode::convertToNodeSpaceAR(const CCPoint& worldPoint); CCPoint CCNode::convertToWorldSpaceAR(const CCPoint& nodePoint);
UI座標系用在觸摸事件的參數中,在重載event
virtual bool ccTouchBegan(CCTouch* touch, CCEvent* event)
函數時,touch中攜帶的座標就是UI座標系,當用來判斷某個精靈是否被點擊時,須要將touch轉爲GL座標系世界座標系和GL座標系是同樣的,在cocos2dx中用這種座標系最多class
節點座標系指以節點左下角爲原點的座標系,用於放置子節點,當某個節點setPosition時,參數所參照的座標便是父節點的座標系touch