setDesignResolutionSize 到竖屏下面就缩放尺寸不对的问题

本文探讨了Cocos2d-x游戏中遇到的竖屏适配问题,主要涉及到setDesignResolutionSize函数在不同屏幕方向下如何正确设置分辨率。分析了frameSize在横竖屏下的变化,并提出了解决方案。
摘要由CSDN通过智能技术生成

    之前做的都是横版的游戏,然后一般使用如下的代码来适配多分辨率:

     

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值