Cocos2d-x Cache

Source: Internet
Author: User

The benefits of using cache are clear to web developers ..

For example, reading data from a database is displayed in the foreground. If you call the database every time, the response time will be extended.

If we set cache for resources and save them in the cache in advance, we can directly read resources from the cache in the program, which can greatly improve the efficiency of game operation;

Before the entry into the main scenario, we set a scenario to set cache for resources in advance;

// SpriteFrameCache: getInstance ()-> addSpriteFramesWithFile ("bg/allbg. plist "); SpriteFrameCache: getInstance ()-> addSpriteFramesWithFile (" mf/mf. plist "); SpriteFrameCache: getInstance ()-> addSpriteFramesWithFile (" vir/vir. plist "); ArmatureDataManager: getInstance ()-> addArmatureFileInfo (" cat/catAnimation. exportJson "); SimpleAudioEngine: getInstance ()-> preloadBackgroundMusic (" music/warring ");


In the home scenario, resources are directly read from our cache;

switch (_tag){    case dirTag:                 {                auto sprite = Sprite::createWithSpriteFrameName("direction.png");                this->addChild(sprite, 2, dirTag);             break;                  }case jumpTag:             {auto sprite = Sprite::createWithSpriteFrameName("tiao.png");            this->addChild(sprite, 2, jumpTag);            break;              }case attTag:            {   auto sprite = Sprite::createWithSpriteFrameName("dangong.png");   this->addChild(sprite, 2, attTag);   break;             }default:break;}

This is much more efficient than reading from folders each time.

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.