Question

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 + +?))

Was it helpful?

Solution

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);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top