[Cocos2d-X (2.x) Game Development Series 3] the latest version of cocos2d 2. 0 x. 0.2 using new resource loading strategy! No longer use the-HD,-iPad,-ipadhd Extension Method

Source: Internet
Author: User

All articles on this site areLi huaming himiOriginal, reprinted must be explicitly noted:
Reprinted from[Heimi gamedev block]Link: http://www.himigame.com/cocos2dx-v2-0/997.html

☞Click to subscribe☜
The latest developments in this blog! Notify you of the latest blog in time!

Some time ago, cocos2dx updated the latest version cocos2d2.0x2.0.2, and changed the policy for resource loading and management from this version.

In the previous loading method is to follow the same way to load resources as cocos2d-iphone, for the image name after adding-HD,-iPad,-ipadhd, after you enable the project's HD retina, you can find the corresponding resources by default. However, since cocos2d2.0x2.0.2, the resource loading policy does not.

The latest resource loading policy mechanism is as follows:

First, find the directory set in setresourcedirectory of ccfileutils. If it cannot be found, find it in the resources/directory.

For example:

1) set the directory:

Ccfileutils: sharedfileutils ()-> setresourcedirectory ("ABC ");

When creating an genie:

Ccsprite * SPR = ccsprite: create(“himi.png ");

Cocos2dx first searches for “himi.png.pdf in the resources/abcdirectory. If it is not found, it will go back to the resourcesdirectory to find “himi.png ".

Therefore, we usually open the HD retina in the applicationdidfinishlaunching function of appdelegate. cpp and add the following code:

Targetplatform target = gettargetplatform (); // obtain the current device type if (target = ktargetipad) {// if it is iPad if (pdirector-> enableretinadisplay (true )) {// If HD retina ccfileutils: sharedfileutils ()-> setresourcedirectory (".. /ipadhd ");} else {ccfileutils: sharedfileutils ()-> setresourcedirectory (".. /iPad ") ;}} else if (target = ktargetiphone) {// for iPhone if (pdirector-> enableretinadisplay (true) {ccfileutils: sharedfileutils () -> setresourcedirectory (".. /HD ");}}

The default directory of the Project is resources. The folders of HD, ipadhd, and iPad created by himi are the same as those of resources. Therefore, the directory is set ".. /HD ",".. /iPad ",".. /ipadhd"

Appendix:

The device enumerated variables are as follows:

Ktargetwindows: Window System

Ktargetlinux: Linux

Ktargetmacos: Mac OS

Ktargetandroid: Android system

Ktargetiphone: IOS-iPhone & itouch

Ktargetipad: IOS-iPad

Ktargetblackberry: BlackBerry System

The himi project directory is shown in 3.14.3.1:

 

Figure 3.14.3.1 project directory

 

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.