Cocos2d-x 3.0 新特性体验(1)创建项目+运行sample+新特性内容

本文介绍了cocos2d-x v3.0 Beta版的新特性,包括C++11特性、移除Objective-C模式、新渲染器、改进的Label和EventDispatcher。此外,还详细讲解了如何在Mac OS X上创建项目,以及新版本带来的变化和已知问题。
摘要由CSDN通过智能技术生成

不得不说,cocos2d-x的版本更迭真是快,而最新的cocos2d-x v3.0 Beta版本中包含了许多新的特性和与之前2.x版本不同的内容,虽然说,目前3.0只是beta版本,但目前很多游戏已经采用这个3.0版本了,估计3.0的最终版本也会很快推出。

从创建项目开始了解一下这个最新的3.0版本的一些新特性吧!吐舌头


一、创建项目(针对在mac os x中进行开发)

在前面我有一篇文章 点击打开链接 已经介绍过在 cocos2dx 2.2 版本中创建项目只能是在终端中进行,对于习惯了在xcode中直接通过项目模板生成项目的来说,这样的方式的确是有点不太方便。

但是在cocos2d-x v3.0 Beta版本中,采用了一种比较人性化图形界面创建方式。

在这里 点击打开链接 有详细的新版本使用介绍。

下面我实践一下如何创建一个 cocos2dx for ios & osx 的项目。(有两种方式)

1、第一种,当然是延续了2.2版本之后的直接命令行创建,这个具体方法可以请参考我之前的文章。点击打开链接

Example:

$ cd cocos2d-x/tools/project-creator
$ ./project-creator.py -n mygame -k com.your_company.mygame -l cpp -p /home/mygame
$ cd /home/mygame

2、第二种,就是图形界面创建的方法
①在终端中,进入引擎文件:cocos2d-x-3.0beta/tools/project-creator
②运行 ./create_project.py 
③在如下图中进行图形界面方式创建项目:

注:大笑 有了这个工具,妈妈再也不用担心我创建cocos2dx项目很麻烦了!想创建项目就直接点击几下就可以了。

二、运行引擎中附带的sample例子
进入 引擎文件: cocos2d-x-3.0beta/build 打开cocos2d_samples.xcodeproj 即可。
注:引擎中附带的例子文件比较大,所有打开和编译运行都需要一点时间,考验机子呀!快哭了

三、cocos2d-x-3.0beta 新特性介绍

注:下面先贴出所有新特性内容,下面的文章,将会根据新特性内容分析详述。

cocos2d-x v3.0 Release Notes

Misc Information

Requirements

Runtime Requirements

  • Android 2.3 or newer
  • iOS 5.0 or newer
  • OS X 10.7 or newer
  • Windows 7 or newer
  • Windows Phone 8 or newer N/A for the moment
  • Linux Ubuntu 12.04 (or newer)
  • Browsers via Emscripten N/A for the moment
  • Marmalade N/A for the moment
  • BlackBerry N/A for the moment

Compiler Requirements

  • Xcode 4.6 (for iOS or Mac)
  • gcc 4.7 for Linux or Android. For Android ndk-r9 or newer is required.
  • Visual Studio 2012 (for Windows)

Highlights of v3.0

  • Replaced Objective-C patters with C++ (C++11) patterns and best practices
  • Improved Labels
  • Improved renderer
  • New Event Dispatcher
  • Physics integration
  • New GUI
  • JavaScript remote debugger
  • Remote Console support
  • Refactor Image - release memory in time and uniform the api of supported file format
  • Automatically generated Lua bindings, add LuaJavaBridge and LuaObjcBridge
  • Templated containers

Features in detail

C++11 features

Feature added in v3.0-pre-alpha0

A subset of C++11 features are being used in cocos2d-x:

  • std::function, including lambda objects for callbacks
  • strongly typed enums, for most of the cocos2d-x enums and constants
  • std::thread for threading
  • override context keyword, for overriden methods

std::function

  • CallFunc can be created with an std::function<void()>
  • CallFuncN can be created with an std::function<void(Node*)>
  • CallFuncND and CallFuncO were removed since it can be created with simulated with CallFuncN and CallFunc. See ActionsTest.cpp for more examples
  • MenuItem supports std::function<void(Node*)> as callbacks

CallFunc example:

// in v2.1
CCCallFunc *action1 = CCCallFunc::create( this, callfunc_selector( MyClass::callback_0 ) );

// in v3.0 (short version)
auto action1 = CallFunc::create( CC_CALLBACK_0(MyClass::callback_0,this));
auto action2 = CallFunc::create( CC_CALLBACK_0(MyClass::callback_1,this, additional_parameters));

// in v3.0 (long version)
auto action1 = CallFunc::create( std::bind( &MyClass::callback_0, this));
auto action2 = CallFunc::create( std::bind( &MyClass::callback_1, this, additional_parameters));

// in v3.0 you can also use lambdas or any other "Function" object
auto action1 = CallFunc::create(
                 [&](){
    
                     auto s = Director::sharedDirector()->getWinSize();
                     auto label = LabelTTF::create("called:lambda callback", "Marker Felt", 16);
                     label->setPosition(ccp( s.width/4*1,s.height/2-40));
                     this->addChild(label);
                 }  );

MenuItem example:

// in v2.1
CCMenuItemLabel *item = CCMenuItemLabel::create(label, this, menu_selector(MyClass::callback));

// in v3.0 (short version)
auto item = MenuItemLabel::create(label, CC_CALLBACK_1(MyClass::callback, this));

// in v3.0 (long version)
auto item = MenuItemLabel::create(label, std::bind(&MyClass::callback, this, std::placeholders::_1));

// in v3.0 you can use lambdas or any other "Function" object
auto item = MenuItemLabel::create(label,
                 [&](Object *sender) {
    
                     // do something. Item "sender" clicked
                  });

strongly typed enums

Feature added in v3.0-pre-alpha0

Constants and enums that started with k, and that usually were defined as 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值