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.