cocos2dx中有几种座标系:
GL座标系以左下角为原点,向上为Y,向左为X
屏幕座标系以左上角为原点,向下为Y,向右为X
屏幕座标系使用的是不同的座标系统,原点在屏幕左上角,x轴向右,y轴向下。iOS的屏幕触摸事件CCTouch传入的位置信息使用的是该座标系。因此在Cocos2D-x中对触摸事件做出响应前,需要首先把触摸点转化到OpenGL座标系。
①从触摸点获取到在屏幕座标系中的座标 // returns the current touch location in screen coordinatesCCPoint CCTouch::() const { return m_point; } ②从触摸点获取到在OpenGL座标系中的座标// returns the current touch location in OpenGL coordinatesCCPoint CCTouch::getLocation() const{ return CCDirector::sharedDirector()->convertToGL(m_point); }