直接上代码
AppDelegate.cpp
</pre><pre name="code" class="cpp">//屏幕适配 Size framSize=glview->getFrameSize();//获取实际屏幕的大小 Size winSize=Size(480,320);//根据实际背景图片的大小,填写 //将宽和高做一个比,通过这个比,来具体调整逻辑分辨率的大小 float widthRate=framSize.width/winSize.width; float heightRate=framSize.height/winSize.height; //如果是if中的语句,说明逻辑的高度有点大了,就把逻辑的高缩小到和宽度一样的比率 if(widthRate>heightRate) { glview->setDesignResolutionSize(winSize.width,winSize.height*heightRate/widthRate,ResolutionPolicy::NO_BORDER); }else { glview->setDesignResolutionSize(winSize.width*widthRate/heightRate,winSize.height,ResolutionPolicy::NO_BORDER); }
调用方法
HelloWorld.cpp
Size visibleSize = Director::getInstance()->getWinSize();
原文链接:https://www.f2er.com/cocos2dx/341938.html