Forum > C++ > c2dx analogs for NSSelectorFromString, NSClassFromString, and respondsToSelector?

c2dx analogs for NSSelectorFromString, NSClassFromString, and respondsToSelector?

By DevSilenti Posted 2011-10-05 10:53 Comments 1
DevSilenti
  • Posts: 8

I’m fairly new to c2dx and I’m looking for anyway I can to import the loading system I wrote for Cocos2d.

Are there any c2dx analogs for NSSelectorFromString, NSClassFromString, and respondsToSelector?

I’m basically trying to convert this code:

- (id) itemWithDict:(NSDictionary*)itemDict withDelegate:(id)del {
    Class type  = NSClassFromString([itemDict objectForKey:@"type"]);

    id newItem;

    if ([type respondsToSelector:@selector(itemFromNormalSprite:selectedSprite:target:selector:)]) {
        SEL itemSel = NSSelectorFromString((NSString*)[itemDict objectForKey:@"selector"]);

        newItem = [type itemFromNormalSprite:[CCSprite spriteWithSpriteFrameName:[itemDict objectForKey:@"img"]
                              selectedSprite:[CCSprite spriteWithSpriteFrameName:[itemDict objectForKey:@"imgSel"]
                                      target:del
                                    selector:itemSel];
    }

    return newItem;
}

And as I’m sure you can imagine I’m running into some trouble.

I’m not looking for a detailed solution but can anyone point me in the right direction with regards to those particular methods? Thanks!

huangrh
  • Posts: 171

#1 RE: 2011-10-17 19:35

hello, c++ is not a runtime progame language, and in cocos2dx, they are not supported either.

about the translating of these methods, you could refer to the test just as:
CCMenuItemSprite* item1 = CCMenuItemSprite::itemFromNormalSprite(spriteNormal, spriteSelected, spriteDisabled, this, menu_selector(MenuLayer1::menuCallback) );
in MenuTest.cpp

Loggin to reply

Copyright © 2010 - 2013 Cocos2d-x.orgClustrmaps