[Cocos2d-x] for different devices, select different adaptive Images

Source: Internet
Author: User

When developing mobile devices, we often prepare image resources of different sizes to adapt to devices of different sizes. I will refer to these resources as puqing image resources and HD image resources. So how can we adapt image resources? Next I will use a demo to demonstrate the implementation of this effect. Tool Introduction: IOS developers have a very useful image synthesis tool, which allows multiple png images to synthesize a large resource image, and can also generate two types of general and high-definition resource images, this tool is TextureParker. How to Use TextureParker to generate resource images open the TP tool, then Add Sprites, Add the image resources you want to Add (preferably png images ), then click the AutoSD option-> Cocos2d-x HD/SD-> Apply. Then, check whether HD/is added to the Data file and Texture file paths. If yes, click Publish to export it. Implementation steps: 1. Create a project file and import the HD and SD folders to the Resources of the Project. 2. Add the adaptive code of the image to the applicationDidFinishLaunching method of AppDelegate.

// Image Adaptive TargetPlatform target = getTargetPlatform (); // if it is an iPhone device if (target = kTargetIphone) {CCSize size = CCEGLView: Export dopenglview ()-> getFrameSize (); if (size. width = 480) {CCFileUtils: sharedFileUtils ()-> addSearchPath ("SD/"); CCLog ("");} else {CCFileUtils: sharedFileUtils () -> addSearchPath ("HD/"); CCLog ("HD ");}}

 

3. Call the image Resource Creation wizard in the main view
CCSize size = CCDirector::sharedDirector()->getWinSize();            CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("pic.plist");      CCSpriteFrame * sp1 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("alien.png");      CCSprite * sp = CCSprite::createWithSpriteFrame(sp1);      sp->setPosition(CCPointMake(size.width/2, size.height/2+40));      this->addChild(sp);  

 

Test: select a device. For example, choose hardware> device> iPhone and iPone3.5 (inch). Different resource effects of the call are displayed.

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.