cocos2d-x CSLoader how to load selected nodes only

543 Views Asked by At

I'm searching for docs on cocos2dx website and on google but i couldn't find any. The problem is, when I load a csb file from cocostudio, it loads all the nodes and its resources etc... it makes the texture memory so high. I would like to know if there is a method or solution for loading only selected nodes from a scene file of cocostudio.

thanks!

2

There are 2 best solutions below

1
On

You can try get a component of the .csb:

auto node = CSLoader::createNode("MainScene/MainScene.csb");
node->getComponent("Star_GameButton")->setEnabled(false);

You need the name of your component ,that is on the porperties on cocos Studio

0
On

I had the same kind of problem, and it stems from trying to make one scene contain everything you need. I decided to split my components into layers, which are then loaded by their own components when needed.

As an example. In my Main Scene I have an inventory tray, a building area and a custom buttons panel. I split all of these into separate layers. InventoryTray.csb, BuildingArea.csb, ButtonPanel.csb and have them all seperate in code as well, one object to load each of the layouts. Overall my code is a lot more maintainable since each class just has a few lines of code in it.

This way I can load my inventory tray up, and not load my buttons panel until the user "needs" to interact with it. The same goes for fancy pause menu's that might include animations and assets that may take up more texture memory. Create it as a separate layer and load it when you need to.

I hope this helps, I never found the cocostudio scenes useful, for anything other than my menu system, since each of the menu scenes that I've built (so far) has been self-contained.