After reading the sample, you will experience cocos2dx in person, but it is inevitable that new people will encounter a dilemma. Although the beginning is bitter, it is wonderful after solving the problem.
I made a small demo and used only one set of images. The resolution of my mobile phone test was different. I ran it directly and only occupied the middle part. I am about to solve the full screen problem.
First, let's take a look at the full-screen HIMI adaptation solution. Add the following comments to main. cpp:
Void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit (JNIEnv * env, jobject thiz, jint w, jint h) {if (! CCDirector: sharedDirector ()-> getOpenGLView () {CCEGLView * view = CCEGLView: Export dopenglview (); view-> setFrameSize (w, h ); // view-> setDesignResolutionSize (320,480, kResolutionExactFit); // force full screen. When the screen width and height are different from the original material ratio, the screen may be squeezed. // View-> setDesignResolutionSize (320,480, kResolutionNoBorder); // when the screen type is different from the original material proportion, the screen edge is removed to avoid image extrusion. // View-> setDesignResolutionSize (320,480, kResolutionShowAll); // when the screen type is different from the original material proportion, the excess part will be filled with black. This method will not cause screen extrusion, however, black edges may appear. AppDelegate * pAppDelegate = new AppDelegate (); CCApplication: sharedApplication ()-> run ();} else {publish (); CCShaderCache: sharedShaderCache ()-> reloaddefashadshaders (); ccDrawInit (); CCTextureCache: ication(); ccicationicationcenter: sharedNotificationCenter ()-> postNotification (success, NULL); CCDirector: sharedDirector ()-> setgldefavalues ();}}After the change, the program runs directly on my I9001 and runs very well (I am very happy), but runs on Nexus4, and the program Crash directly. I am a bit puzzled. I had to go to the cocos2dx forum to post for help. Nobody cares about me.
You can find a solution by yourself.
I ran the HelloCpp in the sample and found that there were also problems with different resolutions. Then I tried to delete the ipad and ipadhd folders in assert and run them again. The application is also Crash.
Really depressing! I was thinking, if there is still no progress today, give up. All programs can run with large images in the sample. Finally, luck was good and I found a clue.
Add the preceding statement under the AppDelegate: applicationDidFinishLaunching () method. Finally, find the appropriate location:
bool AppDelegate::applicationDidFinishLaunching(){ // initialize director CCDirector *pDirector = CCDirector::sharedDirector(); pDirector->setOpenGLView(CCEGLView::sharedOpenGLView()); CCEGLView::sharedOpenGLView()->setDesignResolutionSize(320,480,kResolutionExactFit); // turn on display FPS pDirector->setDisplayStats(true); // set FPS. the default value is 1.0/60 if you don't call this pDirector->setAnimationInterval(1.0 / 60); // create a scene. it's an autorelease object CCScene *pScene = HMenu::scene(); // run pDirector->runWithScene(pScene); return true;}Run again, and the full screen adaptation of the program starts to run. Clear the road and move on!
Only when I look at HelloCpp's AppDelegate can I know that there was an adaptation problem (on my mobile phone, although the background image is full screen, it is not displayed completely), because the following if else:
// Set the design resolution#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionShowAll);#else pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionNoBorder);#endif
ShowAll solutions for WINRT and WP8, while NoBorder solutions for other platforms, cannot be completely displayed.
The following condition judgment statement explains why the program crash occurs after I delete the ipad and ipadhd folders.
// 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 could 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 > mediumResource.size.height) { searchPath.push_back(largeResource.directory); pDirector->setContentScaleFactor(MIN(largeResource.size.height/designResolutionSize.height, largeResource.size.width/designResolutionSize.width)); } // if the frame's height is larger than the height of small resource size, select medium resource. else if (frameSize.height > smallResource.size.height) { searchPath.push_back(mediumResource.directory); pDirector->setContentScaleFactor(MIN(mediumResource.size.height/designResolutionSize.height, mediumResource.size.width/designResolutionSize.width)); } // if the frame's height is smaller than the height of medium resource size, select small resource. else { searchPath.push_back(smallResource.directory); pDirector->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width)); }The program selects an image by comparing the resolution (high), and the appropriate image is deleted by me, of course, the following error is reported.
12-23 19:22:36.249: D/cocos2d-x debug info(6615): Get data from file(CloseNormal.png) failed!12-23 19:22:36.249: D/cocos2d-x debug info(6615): Get data from file(CloseSelected.png) failed!12-23 19:22:36.269: D/cocos2d-x debug info(6615): Get data from file(HelloWorld.png) failed!
In the new environment, it is inevitable that a new person may make mistakes and be overwhelmed. In the process, I still need a process.