问题
Now rewrite the code from cocos2d (objective-c) to cocos2d-x (c + +) and collided with a problem: I have two classes, two CCLayer. In one class there CCMenu by pressing the button calls the second class:
CCMenuItem * button = [CCMenuItemImage itemWithNormalImage: @ "1.png" selectedImage: nil block: ^ (id sender) {
HelloWorldLayer * helloWorldLayer = (HelloWorldLayer *) [self.parent getChildByTag: 777];
[helloWorldLayer createSprite: self];
}];
And in the second grade, I assign Layer tag:
self.tag = 777;
and that method:
- (void) createSprite: (id) sender {
..}
How to rewrite this code in C + +?))
回答1:
It is simple.
Let class in which menu is Class- A
CCMenuItem * button=CCMenuItemImage::create("normal", "selected", "disable", menu_selector(A::Method));
The Method is
void A::Method(CCObject *pSender){
HelloWorldLayer * helloWorldLayer = (HelloWorldLayer *)this->parent->getChildByTag(777);
helloWorldLayer->createSprite(this);
}
来源:https://stackoverflow.com/questions/20378557/rewrite-the-code-cocos2d-objective-c-on-cocos2d-x-c