The most complete tutorial to adapt cocos2d games to IPAD Retina

Source: Internet
Author: User
I haven't found a tutorial on how to quickly adapt an iPhone game developed by cocos2d TO THE ipad2 retina mode on the Internet. Indeed, if you do not plan "one app, multiple adaptation" at the initial stage of the project, it is quite troublesome to do resolution adaptation at the end of the development stage because it involves defining macros, to adapt to the coordinate offset values between different resolutions, You need to modify a large number Code . In addition, many games are designed with a resolution of 480*320/960*640, which is often limited by the interface and logic of the game, it cannot be easily migrated to a resolution of 1024*768 or 2048*1536 of the new iPad. This is also the case for our games. The tutorials we found on the Internet are a few pieces of slogan. As a result, I have taken a lot of detours and now I will record the complete process. 1. First, design the targetd devicefamilly project as an iPhone. This is required. If it is set to iPhone/iPad, You need to define the macro to convert coordinates. 2. Modify the ccctor ctor class of cocos2d and add a property named bool and isipad. Some people don't want to change cocos2d Source code You can also put this property in other classes. However, you will find that modifying the source code of cocos2d cannot be avoided. 3. Open the project's appdelegate. in the M file, search for the applicationdidfinishlaunching method and replace window = [[uiwindow alloc] initwithframe: [uiscreenmainscreen] bounds] with the following code: boolisipad = no; if ([[[uidevice currentdevice] model] rangeofstring: @ "iPad"]. location! = Nsnotfound) {isipad = yes;} // init the latest WIF (isipad) {window = [[uiwindow alloc] initwithframe: cgrectmake (640,960,)];} else {window = [[uiwindow alloc] initwithframe: [[uiscreen mainscreen] bounds];} Then search for ccdirector * Director = [ccdirector shareddire, add a line of code below: Director. isipad = isipad; 4. Open ccdirectorios in cocosc2d. M file, search if ([[uiscreen mainscreen] scale] = 1.0) return no; Replace with if ([uiscreen Mainscreen] scale] = 1.0 &&! Isipad) return no; 5. Open ccfileutils of cocos2d. M file, find the + (nsstring *) getdoubleresolutionimage :( nsstring *) path method, and change if (cc_content_scale_factor () = 2) of the second line to If (cc_content_scale_factor () = 2 | [ccdirector shareddire]. isipad) 6. In the last step, open the project's rootviewcontroller. m, locate-(void) willrotatetointerfaceorientation :( uiinterfaceorientation) tointerfaceorientationduration :( nstimeinterval) Duration method, in cgrect screenrect = [[UIS Creen mainscreen] bounds]; add If ([ccdirector shareddire] under this line of code. isipad) {screenrect = cgrectmake (0, 0,640,960);} run the app on the iPad to see if it is already using HD image resources. However, although this method is fast and secure, there are two shortcomings: first, it is not displayed in full screen on the iPad, but there is a black space around it, because only 960*640 of the space is occupied, and the other is because the targetd device familly of the project is set to the iPhone, the default running method is 1x when running on the iPad, you need to click the icon in the lower-right corner of the iPad to manually switch to 2x mode.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.