加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

cocos2d-x3.x之helloWorld

发布时间:2020-12-14 19:19:27 所属栏目:百科 来源:网络整理
导读:刚接触到cocos2d-x3.2版本,发现3.x与2.x版本有很大差别,看下面一段代码 auto closeItem = MenuItemImage::create( "CloseNormal.png","CloseSelected.png",CC_CALLBACK_1(HelloWorld::menuCloseCallback,this)); 我们明显发现,多了一个 自动类型变量auto

刚接触到cocos2d-x3.2版本,发现3.x与2.x版本有很大差别,看下面一段代码

auto closeItem = MenuItemImage::create(
                                           "CloseNormal.png","CloseSelected.png",CC_CALLBACK_1(HelloWorld::menuCloseCallback,this));

我们明显发现,多了一个 自动类型变量auto,同时,由CCMenuItemImage变成了MenuItemImage。

我们在这里改一下:

auto closeItem = MenuItemImage::create(
                                           "CloseNormal.png",[](Object *sender)
	   {
		    #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
				MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert");
				return;
			#endif

				Director::getInstance()->end();

			#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
				exit(0);
			#endif
	   });
编译运行程序,编译通过,我们知道,cocos2dx3.0配合c11标准,使得代码逻辑更加紧凑。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读