rewrite the code cocos2d (objective-c) on cocos2d-x (c++)

早过忘川 提交于 2020-01-14 06:55:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!