This problem has been solved for several days. Here is a summary:
First, we agree to apply only one set of image resources to both iPhone 4 and iPhone 5 (the image can be displayed normally even on the ipad). Here we will make the background that needs to be displayed in full screen as the size of iPhone 5: 1136*640
I. cocosbuilder
1. Create a new scenario file and select iPhone 5 Landspcape to adjust the height to 1136*640:
Only one set of images is needed.
2. Set all nodes in the scenario as percentage coordinates:
2. coco2d-x
In our scenario, the size is 1136*960, and the ratio of the actual screen size to the design size to the height is used as the scaling factor. The Code is as follows:
CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize(); CCSize designSize = CCSizeMake(1136, 640); CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils(); std::vector<std::string> searchPaths; pFileUtils->setSearchPaths(searchPaths); pDirector->setContentScaleFactor(screenSize.height/screenSize.height); CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionNoBorder); CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize(); CCSize designSize = CCSizeMake(1136, 640); CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils(); std::vector<std::string> searchPaths; pFileUtils->setSearchPaths(searchPaths); pDirector->setContentScaleFactor(screenSize.height/screenSize.height); CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionNoBorder);
The above method can be properly displayed in four simulators: iphone Retina (3.5-inch), iphone Retina (4-inch), ipad, and ipad Retina, and the location is correct.
Only when the ipad Retina image is enlarged will it be distorted.