Recently in the use of cocos2d-x boot interface, 2dx version is 2.2.3, scene switching with the effect, all resources have been used texturepacker package preload, but in the actual running debugging, scenario switching is rather choppy.
After a variety of confusions, the frame rate printing (setdisplaystats (true) is unintentionally released, and a serious problem is found that the number of objects has been increasing, resulting in a continuously decreasing frame rate, by the time the scenario is switched, it will be completely unable to run. After carefully checking the code, I found that in the scenario frame loop (Update (), I monitored the network status of the mobile phone, removed some genie according to the network status, and then created and displayed some genie, the problem lies here.
Void skyguidesecondpage: Update (float delta) {char wlan_state [16] = {0}; property_get ("coocaa. wlan_state ", wlan_state," 0 "); int wlanstate = atoi (this-> guideinfo. wlan_state); If (wlanstate = 1) {This-> removechildbytag (214); ccsprite * sp_connecting = ccsprite: createwithspriteframe (ccspriteframecache: equals () -> spriteframebyname ("guide_connecting_ttf"); sp_connecting-> setanchorpoin T (CCP (0, 1); sp_connecting-> setposition (CCP (1640,175 0); sp_connecting-> setscale (1.5f); this-> addchild (sp_connecting ); // If the wlanstate is equal to 1 at the beginning of a certain time point, a sp_connecting genie will be created for each frame starting from this frame, and the frame is cyclically 40 times per second, then, 40 identical genie are created every second, and all the consumption is increased. When switching the scenario, it is definitely stuck. Therefore, you need to add a status judgment here, ensure that sp_connecting is created only once .}
Modified code:
Void skyguidesecondpage: Update (float delta) {char wlan_state [16] = {0}; property_get ("coocaa. wlan_state ", wlan_state," 0 "); int wlanstate = atoi (this-> guideinfo. wlan_state); If (wlanstate = 1) {If (this-> connectflag = 0) // The initial status is 0, and the status judgment is {This-> connectflag = 1; // set the status to 1 so that the next frame cannot be entered. The genie sp_connecting will not be created again with this-> removechildbytag (214); ccsprite * sp_connecting = ccsprite :: createwithspriteframe (ccspriteframecache: sharedspriteframecache ()-> spriteframebyname ("ing"); sp_connecting-> setanchorpoint (CCP (0, 1 )); sp_connecting-> setposition (CCP (500,400); sp_connecting-> setscale (1.5f); this-> addchild (sp_connecting );}}
Cocos2d-x frame loop is not rigorous, causing scene switching to lag