Multi-resolution support for all Android devices

I am porting my game to cocos2d iPhone on android using cocos2d-x. I ran into a screen resolution problem: I want to use one high-resolution image in my game, which should be supported by all screens below a given resolution.

I read this good multi-resolution tutorial on the forum. This is really useful, but I am not reaching my solution. There is an explanation of the scale factor of resource design resolution and resource resolution.

But in my case, it scales both in height and in width. Not perfect scaling of my image. Can someone clarify why for me?

+4
source share
4 answers

In AppDeligate.cpp, add the following lines to

bool AppDelegate :: applicationDidFinishLaunching () after installing glview.

CCEGLView *ev = CCEGLView::sharedOpenGLView(); ev->setDesignResolutionSize(480, 320, kResolutionShowAll); 

480, 320 - resolution for which you developed your application. If you want to use portfolio 320, 480. This solution will show black borders if the aspect ratio of the phone does not match the aspect ratio of 480/320.

+3
source

In AppDelegate.cpp

This is for landscape mode

 bool AppDelegate::applicationDidFinishLaunching() { // initialize director director = CCDirector::sharedDirector(); EGLView = CCEGLView::sharedOpenGLView(); director->setOpenGLView(EGLView); CCSize screenSize = EGLView->getFrameSize(); CCSize designSize = CCSizeMake(800, 480); EGLView->setDesignResolutionSize(designSize.width,designSize.height, kResolutionExactFit); if(screenSize.height > 480 && screenSize.height < 720 ) { CCSize resourceSize = CCSizeMake(960, 540); director->setContentScaleFactor(resourceSize.height/screenSize.height); CCLog("Resolution Scale OF Karboon=%f",resourceSize.width/screenSize.width); } else if (screenSize.height >= 720 && screenSize.height < 800) { CCSize resourceSize = CCSizeMake(1280, 720); director->setContentScaleFactor(resourceSize.height/screenSize.height); CCLog("Resolution Scale OF NOTE=%f",resourceSize.width/screenSize.width); } else if(screenSize.height > 800) { CCSize resourceSize = CCSizeMake(1920, 1080); director->setContentScaleFactor(resourceSize.height/screenSize.height); CCLog("Resolution Scale OF Nexus=%f",resourceSize.width/screenSize.width); } else { director->setContentScaleFactor(1); CCLog("Resolution Scale OF S Advance=%f"); } return true; } 
+1
source

Here is some code that can help you make the following folders in the Resource folder

ipadhd ipad iphone

Use this code in Appdelegate.cpp in the applicationdidfinishing method

  CCSize screenSize = pEGLView->getFrameSize(); //set design size for iPad retina CCSize designSize = CCSize(2048, 1536); CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionExactFit); if (screenSize.height > 768) { CCFileUtils::sharedFileUtils()->setResourceDirectory("ipadhd"); } else if (screenSize.height > 320) { CCFileUtils::sharedFileUtils()->setResourceDirectory("ipad"); } else { CCFileUtils::sharedFileUtils()->setResourceDirectory("iphone"); } pDirector->setContentScaleFactor(screenSize.height/designSize.height) 

Hope this helps. Place the images on iphone respectively in the iphone folder, ipad images in ipad folder and hd images in ipadhd folder. pDirector here is a CCDirector variable.

0
source

I followed this good tutorial http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Multi_resolution_support

So it worked for me. I used one high resolution image

Appdelegate.cpp

 typedef struct tagResource { cocos2d::CCSize size; char directory[100]; }Resource; static Resource smallResource = { cocos2d::CCSizeMake(320,480), "iphone" }; static Resource mediumResource = { cocos2d::CCSizeMake(768,1024), "ipad" }; static Resource largeResource = { cocos2d::CCSizeMake(1536,2048), "ipadhd" }; static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(640,1024); CCEGLView* pEGLView = CCEGLView::sharedOpenGLView(); CCSize frameSize = pDirector->getOpenGLView()->getFrameSize(); pEGLView->setDesignResolutionSize( designResolutionSize.width, designResolutionSize.height, kResolutionExactFit); if ((frameSize.height > mediumResource.size.height)) { pDirector->setContentScaleFactor(largeResource.size.height/designResolutionSize.height); } // if the frame height is larger than the height of small resource size, select medium resource. else if ((frameSize.height > smallResource.size.height)) { pDirector->setContentScaleFactor(mediumResource.size.height/designResolutionSize.height); } // if the frame height is smaller than the height of medium resource size, select small resource. else { pDirector->setContentScaleFactor(smallResource.size.height/designResolutionSize.height); } CCDirector::sharedDirector()->setContentScaleFactor(1.f); 
0
source

Source: https://habr.com/ru/post/1494294/


All Articles