«

»

Aug 24

Cocos2dx Migration -> 2nd update (8 hours)

Right now we have the basics of the menus all loaded, and the main game screen is now loaded and displaying some of the core assets. I did hit an issue on the cocos2dx code, not sure why but for now I reverted back to the original code. I’ll summarize below.

Cocos2d-x has a cool constructor for it’s core objects, instead of multiple different constructors depending on your argument, you can now just call the same one, and feed in your arguments. In plain english…

To create a sprite from a sprite frame name we used to do this:
CCSprite *sprite = CCSprite::spriteWithSpriteFrameName(“frameName.png”);
Create a sprite from a file:
CCSprite *sprite = CCSprite::spriteWithFile(“frameName.png”);
Now we can just do this
CCSprite *sprite = CCSprite::create(“frameName.png”);

The new create() has now replaced just about every constructor in 2.0.x. I found it really easy to use mainly because I’m used to all the constructors and cocos2d lingo, it could be a bit overwhelming if you don’t know cocos2d that much, because it’s nondescript. But I found it easy to use, until it didn’t work.

The issue I had was the one above, adding a sprite frame name from a sprite sheet added to the cache, it didn’t work. So, I had to revert to the original call, spriteWithSpriteFrameName(“frameName.png”);. I’ll keep watching the cocos2d-x source and see if a fix comes in, or better yet understand if I did something wrong. As I’m using the old style, it’s marked as deprecated, so I’ll be reminded to check for updates along the way.

Aside from that hiccup, things are going well, and we have 40 hours to go. Most of the core logic is ported, once the main view is up, we have some custom scrolling views we’ll need to port over which I presume will be time consuming.

Leave a Reply