屏幕适配:
CCSize VisibleSize =CCDirector::sharedDirector()->getVisibleSize();//可视大小; CCSize WinSize =CCDirector::sharedDirector()->getWinSize();//窗口大小;
这两个值相等;
测试的时候可以用%g 来获取值;
CCSprite * map = CCSprite::create(“bg”); Map->setTextureRect(CCRectMak(0,winSize.wdith,winSize.height));
这时候可以用设置比例的方法来设置大小;
设置AppDelegate.cpp的屏幕适配;
CCDirector * pDirector =CCDirector::sharedDirector(); CCEGLView * pEGLView =CCEGLView::sharedOpenGLView(); pDirector->setOpenGLView(pEGLView); pEGLView->setDeSignResolutionSize(480,800,kResolutionFixedHeight);//根据屏幕高来设置比例;
---这时候可能会导致图片有所缩减;多出的还是存在,只是不显示;
CCSprite * map = CCSprite::create(“bg”); map1->setScale(VisibleSize.height/map1->getContentSize().height);
kResolutionExactFit:强制拉伸;会导致图片比例失真;
kResolutionNoBorder:等比例拉伸;会有一部分跑到屏幕外面去;
kResolutionShowAll:保持比例,全显示图片,会导致黑边;
kResolutionFixedHeight:固定高度;
kResolutionFixedWidth:固定宽度;
CCPoint origin =CCDirector::sharedDirector()->getVisibleOrigin();
原文链接:https://www.f2er.com/cocos2dx/345672.html