在 cocos2d-x (c++) 上重写代码 cocos2d (objective-c) [英] rewrite the code cocos2d (objective-c) on cocos2d-x (c++)

查看:19
本文介绍了在 cocos2d-x (c++) 上重写代码 cocos2d (objective-c)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

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);
}

这篇关于在 cocos2d-x (c++) 上重写代码 cocos2d (objective-c)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆