cocos2d-x3.x之helloWorld

前端之家收集整理的这篇文章主要介绍了cocos2d-x3.x之helloWorld前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

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

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

我们在这里改一下:

  1. auto closeItem = MenuItemImage::create(
  2. "CloseNormal.png",[](Object *sender)
  3. {
  4. #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
  5. MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert");
  6. return;
  7. #endif
  8.  
  9. Director::getInstance()->end();
  10.  
  11. #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
  12. exit(0);
  13. #endif
  14. });
编译运行程序,编译通过,我们知道,cocos2dx3.0配合c11标准,使得代码逻辑更加紧凑。

猜你在找的Cocos2d-x相关文章