Search code examples
ioscocos2d-iphonecocos2d-xobjective-c++

migrating cocos2dx to v2.1.5


First of all, I know this is such an outdated version. But I really need an answer. I'm very new to iOS and cocos2dx, I just got some old code and I'm trying to update cocos2dx to v2.1.5.

My problem is CCMutableArray has been deprecated, replaced with CCArray. I know that in the latest version CCArray has also been deprecated.

But my question is how do I properly update this part of the code without getting unexpected results...

static CCMutableArray<CCString*>* getCsvList(string path);
CCMutableArray<GiftInfo*>* giftList;

I believe I can't just do a drop-in replace like:

static CCArray<CCString*>* csvList(string path);
CCArray<GiftInfo*>* giftList;

Thanks.


Solution

  • you can use CCArray like this

    static CCArray* csvList( string path );
    CCArray* giftList;
    CCArray* stringList;
    //
    //
    //you can add object of CCObject class or derived from CCObject class to CCArray
    //example
    GiftInfo* gift = GiftInfo::create();
    giftList->addObject(gift); //GiftInfo must derived from CCObject class
    
    CCString* myString = CCString::create("new string");
    stringList.addObject(myString);
    
    //when getting value from CCArray, it will return object of CCObject, you have to cast it to your class
    CCString* getValue = (CCString*)stringList.objectAtIndex( index );
    GiftInfo* getGift = (GiftInfo*)giftList.objectAtIndex( index ); 
    

    for more information see CCArray class inside cocos2d-x code.

    Note: It is better to updatre to version 2.2.6 instead of 2.1.5, Its is latest version of cocos2d-x 2.x series.