Any plans for a sample loader for cocos2d-x

What would you like to see in future versions of the editor?
Post Reply
zaphr
Posts: 4
Joined: Mon Jun 24, 2013 2:38 am

Any plans for a sample loader for cocos2d-x

Post by zaphr »

Are there any plans to write a sample loader for cocos2d-x in c++?

I was previously using the objective c++ sample loader for straight cocos2d but I have been struggling to convert it over to c++ since switching to cocos2d-x. Mainly due to hitting the limits of my current c++ experience =/

I also attempted to use the c++ testbed as a starting point but couldn't work out how it would map to a cocos2d-x project.

Any pointers for how to go about it?
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Any plans for a sample loader for cocos2d-x

Post by iforce2d »

The b2dJson in the cocos2d project is already C++, so there isn't really anything you would need to change afaik.
I have not used cocos2d-x but I was under the impression that it follows all the same API and methods as cocos2d, so I would not have thought it to have much to get stuck on. If you could give us some pointers about what specifically you are getting stuck with, that might help as a starting point.
zaphr
Posts: 4
Joined: Mon Jun 24, 2013 2:38 am

Re: Any plans for a sample loader for cocos2d-x

Post by zaphr »

Thanks.

Actually making progress, managed to get b2djson loading the json into a world object so hopefully should be able to sort the rest out this weekend.

You're right that cocos2d-x is pretty similar to cocos2d but the api looks to be diverging over time. They are working on v3 at the moment and planning on removing many of the objective-c patterns from the framework (for good or bad). I guess the api will continue to diverge.


I'm trying to get RUBE json loading going on iOS and android in parallel with cocos2dx, testing on both as I go along.

One issue I had on android but not iOS was with b2dJson readFromFile failing. I'll just dump the brief details here in case it helps anyone who hits this in future!

For some reason CCFileUtils::sharedFileUtils()->fullPathForFilename() only seems to return a relative path on android and I couldn't work out any way to get an absolute path. I'm guessing this may have been the cause for b2dJson readFromFile failing but could well have been some permissions issue.

One workaround that is working for me on both iOS and android is to use cocos2dx to read the file into a char*, convert to std::string and then use b2djson readFromString. I'm still relatively new to c++ so I'm sure there must be a cleaner way to do it =)

Code: Select all

    b2dJson json;
    unsigned long tmpSize;
    unsigned char* jsonString = CCFileUtils::sharedFileUtils()->getFileData("example.json", "r", &tmpSize);
    std::string jsonStdString(jsonString, jsonString + tmpSize);
    std::string errMsg;
    m_world = json.readFromString(jsonStdString, errMsg);
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Any plans for a sample loader for cocos2d-x

Post by iforce2d »

Good to hear you're progressing :) b2dJson::readFromFile should return some info in the errorMsg parameter about why it failed, or you can just step through the code to find out.
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Any plans for a sample loader for cocos2d-x

Post by iforce2d »

Just to follow up on this, msm1982 has pointed out a change that needs to be made for Android, which is probably the cause of your problem:
viewtopic.php?f=7&t=209

There is also now a sample loader for cocos2d-X here: http://www.iforce2d.net/rube/?panel=loaders
Post Reply