Half a month did not update the blog, from the project began to learn a lot of details of things, are not very system, but it is the development of the online must experience things. For example, the right asynchronous loading in the Super Marie series (i), proper layering, proper compositing and loading of plist, timely removal of unused caches, the resources required to dynamically load the current level according to the level.
This chapter only shares the logic of asynchronous loading, if there is a wrong place also hope that you point out in time.
Currently, there are four types of resources in my code that need to be loaded asynchronously:
1.png single PNG in less case
Packaged resources with 2.plist and PNG
Packaging resources for 3.plist and PVR.CCZ
4.CocosStudio exported. exportjson suffix Animation file
Repeat the loading mechanism: all resources are loaded sequentially and cannot load multiple files at the same time. The process of performing an asynchronous load is definitely written in void update (float f) and is loaded by frame.
asynchronous loading of 1.png
[CPP] view plain copy print? Director::getinstance ()->gettexturecache ()->addimageasync (Reloadimages[curreloadimgnum], CC_CALLBA Ck_1 (Loadingscene::imageasynccallback, this));
packaged resources with 2.plist and PNG
Not much nonsense, directly on the method, without loading the Plist API, we use a method such as 1 to load PNG, and then load the plist in the callback function.
[CPP] view plain copy print? Director::getinstance ()->gettexturecache ()->addimageasync (reloadplists[curreloadplistnum]+ "PNG", C C_callback_1 (loadingscene::p listimageasynccallback, this));
Note the parameters of the callback function, which is the key to plist asynchronous loading, and the formal parameter is a PNG texture.
[CPP] view plain copy print? void Loadingscene::p listimageasynccallback (cocos2d::texture2d* texture) {spriteframecache::getinstance ()->addS Priteframeswithfile (Reloadplists[curreloadplistnum].append ("plist"), texture); curreloadplistnum++; Loading = true; }
Packaging resources for 3.plist and PVR.CCZ
A method similar to 2.
[CPP] view plain copy print? Director::getinstance ()->gettexturecache ()->addimageasync (Reloadpvrplists[curreloadpvrplistnum] + "Pvr.ccz ", Cc_callback_1 (loadingscene::p vrplistimageasynccallback, this)); void Loadingscene::p vrplistimageasynccallback (cocos2d::texture2d* texture) {spriteframecache::getinstance ()->a Ddspriteframeswithfile (Reloadpvrplists[curreloadpvrplistnum].append ("plist"), texture); curreloadpvrplistnum++; Loading = true; }
4.CocosStudio exported. exportjson suffix Animation file
[CPP] View plain copy print? Armaturedatamanager::getinstance ()->addarmaturefileinfoasync (Reloadexportjsons[curreloadexportjsonnum], This, schedule_selector (loadingscene::jsonasynccallback)); Void loadingscene:: Jsonasynccallback (float f)