Saturday, January 04, 2014

Automating CCB Creation

Cocos2d-x is awesome because you can use cocosbuilder for creating scenes / animations with ease. But there could be scenarios where you want to create multiple CCB (cocosbuilder files) like

1) Same animation but different images
     You might want to create a large number of ccb files with different images but same animations. This could be done in the code as well but this would make it easier.
2) Create a starting point for animation.
    If you had to move the images around in the ccb but you know for sure that all the images have to be dragged into the scene and animated.

So how do we do this?...

Well the "CCB" files are nothing but XML files to be more precise they are PLIST files. So all you have to do is create these XML files using a script of some sort so your manual labour is reduced.

Python was the language of choice here because it's very versatile at doing things like these. I was going to use the xml Etree module for handling this but i quickly realized that it was going to be a nightmare if i didn't have a library that could understand and use plists directly. That is when i found the plistlib which has enabled me to manipulate / update the "CCB" files much easier.

With these in hand a couple of template "CCB" files i was able to quickly generate the target "CCB" files with a single script. Pretty neat :) This is going to be crucial for our Comic Next framework.