之前做的都是横版的游戏,然后一般使用如下的代码来适配多分辨率:
typedef struct tagResource
{
CCSize sizeInPixel;
CCSize sizeDesign;
char directory[100];
}Resource;
static Resource resPhone = { CCSizeMake(480, 320), CCSizeMake(480, 320), "iphone" };
static Resource resPhoneRetina = { CCSizeMake(960, 640), CCSizeMake(480, 320), "iphonehd" };
static Resource resPhone5Retina = { CCSizeMake(1136, 640), CCSizeMake(568, 320), "iphonehd" };
static Resource resTable = { CCSizeMake(1024, 768), CCSizeMake(512, 384), "ipad" };
static Resource resTableRetina = { CCSizeMake(2048, 1536), CCSizeMake(512, 384), "ipadhd" };
然后在 cocos的
bool AppDelegate::applicationDidFinishLaunching()函数中,通过如下的代码来适配:
// initialize director
CCDirector *pDirector = CCDirector::sharedDirector();
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
//设置素材目录
CCSize frameSize = pEGLView->getFrameSize();
Resource actualResource;
float actualHeight = fmin(frameSize.width, frameSize.height);
float actualWidth = fmax(frameSize.width, frameSize.height);
if (actualHeight > resTable.sizeInPixel.height)
{
actualResource = resTableRetina;
}
else if (actualHeight > resPhoneRetina.sizeInPixel.height)
{
actualResource = resTable;
}
else if (actualHeight > resPhone.sizeInPixel.height)
{
actualResource = resPhoneRetina;
if (actual