轉自:http://home.cnblogs.com/group/topic/57609.html
cocos2d坐標系(OPenGL坐標系):以左下角為原點,x向右,y向上
屏幕坐標系(android,ios,win32系統的坐標系):以左上角為原點,X軸向右為正,y軸向下為正
在cocos2dx的test例子中:
void TestController::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent) { CCSetIterator it = pTouches->begin(); CCTouch* touch = (CCTouch*)(*it); CCPoint m_tBeginPos = touch->locationInView(); m_tBeginPos = CCDirector::sharedDirector()->convertToGL( m_tBeginPos ); }
CCTouch中觸摸點的位置是使用屏幕坐標系的,
convertToGL把屏幕坐標系的點的位置轉成OPengl坐標系的位置
OPenGL坐標系和屏幕坐標系都是x最大值不超過窗口的寬,y最大值不超過窗口的高,也就是屏幕向上或向下滾動后,坐原點是固定的,不會隨屏幕滾動