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); }