在触摸事件中,需要获得触点的地址,需要转换为openGL的坐标:
CCPoint endPoint = CCDirector::sharedDirector()->convertToGL(pTouch->getLocationInView());
触摸事件中,如果是单点触摸,在registerWithTouchDispatcher()中,调用:
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,0,false);
多点触摸则调用:
CCPoint endPoint = CCDirector::sharedDirector()->convertToGL(pTouch->getLocationInView());
触摸事件中,如果是单点触摸,在registerWithTouchDispatcher()中,调用:
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,0,false);
多点触摸则调用:
CCDirector::sharedDirector()->getTouchDispatcher()->addStandardDelegate(this,0);
eglView->setFrameSize(320, 640);
run一下项目,发现没有做屏幕尺寸的适配
现在,在AppDelegate.cpp中继续添加代码
#define _SCREEN_BASIC_WIDTH_ 768
在applicationDidFinishLaunching()方法中pDirector->setOpenGLView(pEGLView);代码的下边添加以下代码
//获得设备分辨率
CCSize sizeView = pEGLView->getFrameSize();
//校验设备分辨率参数
if(sizeView.width==0)
{
CCMessageBox("Error:Can't get Device!","<Error>");
pDirector->end();
}
//按屏幕计算出新高度
int nNewHeight = (sizeView.height)*_SCREEN_BASIC_WIDTH_/sizeView.width;
//自适应分辨率(这样不论手机屏幕是怎样的,都不会留黑边)
pEGLView->setDesignResolutionSize(_SCREEN_BASIC_WIDTH_,nNewHeight,kResolutionExactFit);