The 2d-x version is 2.1.1. The current project requires that iphone, iphone Retina, ipad, and ipad Retina have their own paths to store their own resources. In AppDelegate
The applicationDidFinishLaunching () function is set based on the screen resolution.
Static Resource iPhoneResource = {CCSizeMake (480,320), "iPhone "};
Static Resource iPhoneHDResource = {CCSizeMake (480*2,320*2), "iPhoneHD "};
Static Resource iPhoneTallerResource = {CCSizeMake (1136,640), "iPhoneTaller "};
Static Resource iPadResource = {CCSizeMake (1024,768), "iPad "};
Static Resource iPadHDResource = {CCSizeMake (2048,153 6), "iPadHD "};
Static CCSize designResolutionSize = CCSizeMake (480,320 );
Static CCSize designTallerResolutionSize = CCSizeMake (568,320 );
Static CCSize designIpadResolutionSize = CCSizeMake (512,384 );
Bool AppDelegate: applicationDidFinishLaunching ()
{
// Initialize director
CCDirector * pDirector = CCDirector: shareddire ();
CCEGLView * pEGLView = CCEGLView: Export dopenglview ();
PDirector-> setOpenGLView (pEGLView );
Std: vector <std: string> searchPath = CCFileUtils: sharedFileUtils ()-> getSearchPaths ();
// Set the design resolution
PEGLView-> setDesignResolutionSize (designResolutionSize. width, designResolutionSize. height, kResolutionNoBorder );
CCSize designSize = designResolutionSize;
CCSize frameSize = pEGLView-> getFrameSize ();
_ IsLongiPhone = false;
_ IsIpadHD = false;
_ IsIpadNormal = false;
// In this demo, we select resource according to the frame's height.
// If the resource size is different from design resolution size, you need to set contentScaleFactor.
// We use the ratio of resource's height to the height of design resolution,
// This can make sure that the resource's height cocould fit for the height of design resolution.
// If the frame's height is larger than the height of medium resource size, select large resource.
If (frameSize. height = iPadHDResource. size. height & frameSize. width = iPadHDResource. size. width)
{
SearchPath. push_back (iPadHDResource. directory );
SearchPath. push_back (iPhoneHDResource. directory );
DesignSize = designIpadResolutionSize;
PEGLView-> setDesignResolutionSize (designSize. width, designSize. height, kResolutionNoBorder );
PDirector-> setContentScaleFactor (iPadHDResource. size. height/designIpadResolutionSize. height );
_ IsIpadHD = true;
}
// If the frame's height is larger than the height of small resource size, select medium resource.
Else if (frameSize. height = iPadResource. size. height & frameSize. width = iPadResource. size. width)
{
SearchPath. push_back (iPadResource. directory );
SearchPath. push_back (iPhoneHDResource. directory );
DesignSize = designIpadResolutionSize;
PEGLView-> setDesignResolutionSize (designSize. width, designSize. height, kResolutionNoBorder );
PDirector-> setContentScaleFactor (iPadResource. size. height/designIpadResolutionSize. height );
_ IsIpadNormal = true;
}
// If the frame's height is smaller than the height of medium resource size, select small resource.
Else if (frameSize. height = iPhoneResource. size. height & frameSize. width = iPhoneResource. size. width)
{
SearchPath. push_back (iPhoneResource. directory );
SearchPath. push_back (iPhoneHDResource. directory );
PDirector-> setContentScaleFactor (iPhoneResource. size. height/designResolutionSize. height );
}
Else if (frameSize. height = iPhoneHDResource. size. height & frameSize. width = iPhoneHDResource. size. width ){
SearchPath. push_back (iPhoneHDResource. directory );
PDirector-> setContentScaleFactor (iPhoneHDResource. size. height/designResolutionSize. height );
DesignSize = designResolutionSize;
PEGLView-> setDesignResolutionSize (designSize. width, designSize. height, kResolutionNoBorder );
}
Else if (frameSize. height = iPhoneTallerResource. size. height & frameSize. width = iPhoneTallerResource. size. width ){
// Push taller resources "directory first, so look for resources in taller resources" directory first
SearchPath. push_back (iPhoneTallerResource. directory );
SearchPath. push_back (iPhoneHDResource. directory );
DesignSize = designTallerResolutionSize;
PEGLView-> setDesignResolutionSize (designSize. width, designSize. height, kResolutionNoBorder );
PDirector-> setContentScaleFactor (iPhoneTallerResource. size. height/designResolutionSize. height );
_ IsLongiPhone = true;
}
CCFileUtils: sharedFileUtils ()-> setSearchPaths (searchPath );
}
After the path is set, the required resources will be searched in SearchPaths when you enter the game. Note that the resource files in each path are the same. You do not need to add the-HD suffix based on whether Retina is not available.