cocos2dx3.0创建项目12怎么创建显目

shahdza 的BLOG
用户名:shahdza
文章数:114
评论数:74
访问量:262294
注册日期:
阅读量:5863
阅读量:12276
阅读量:316268
阅读量:1029180
51CTO推荐博文
【唠叨】&&&&在2.x中处理事件需要用到委托代理(delegate),相信学过2.x的触摸事件的同学,都知道创建和移除的流程十分繁琐。&&&&而在3.x中由于加入了C++11的特性,而对事件的分发机制通过事件分发器EventDispatcher 来进行统一的管理。&&&&事件监听器主要有:&&&&& 触摸事件 & & : EventListenerTouchOneByOne、EventListenerTouchAllAtOnce&&&&& 鼠标响应事件 :&EventListenerMouse&&&&& 键盘响应事件 :&EventListenerKeyboard&&&&& 加速计事件 & :&EventListenerAcceleration&&&&& 自定义事件 & :&EventListenerCustom&&&&& 物理碰撞事件 :&EventListenerPhysicsContact&&&&& 游戏手柄事件 :&EventListenerController【致谢】&&&& &&&& 【事件分发器】&&&&事件分发器EventDispatcher,用于统一管理事件监听器的所有事件的分发。1、_eventDispatcher&&&&_eventDispatcher是Node的属性,通过Director::getInstance()-&getEventDispatcher() 获得。&&&&_eventDispatcher的工作由三部分组成:& & & (1)事件分发器 :EventDispatcher。& & & (2)事件类型 & :EventTouch, EventKeyboard 等。& & & (3)事件监听器 :EventListenerTouch, EventListenerKeyboard 等。&&&&监听器实现了各种触发后的逻辑,在适当时候由事件分发器分发事件类型,然后调用相应类型的监听器。2、添加/删除监听器&&&&添加监听器:addEventListenerWithSceneGraphPriority ,& & & & & & & &&addEventListenerWithFixedPriority 。&&&&删除监听器:removeEventListener ,& & & & & & & &&removeAllEventListeners 。3、主要函数&&&&包含监听器的添加、删除、暂停、恢复,优先级的设置,手动分发事件等。//
class&EventDispatcher&:&public&Ref
&* 添加监听器
-&addEventListenerWithSceneGraphPriority
-&addEventListenerWithFixedPriority
-&addCustomEventListener
//使用&场景图的优先级&为指定事件添加一个监听.&
//listener&:&指定要监听的事件.
//node&&&&&:&这个节点的绘制顺序是基于监听优先级.&
//优先级&&&:&0
void&addEventListenerWithSceneGraphPriority(EventListener*&listener,&Node*&node);
//使用&一定的优先级&为指定事件添加一个监听.&
//listener&&&&&&:&指定要监听的事件.&
//fixedPriority&:&这个监听器的固定优先级.
//优先级&&&&&&&&:&fixedPriority。(但是不能为0,因为他是场景图的基本优先级)
void&addEventListenerWithFixedPriority(EventListener*&listener,&int&fixedPriority);
//用户自定义监听器
EventListenerCustom*&addCustomEventListener(const&std::string&&eventName,&const&std::function&void(EventCustom*)&&&callback);
&* 删除监听器
-&removeEventListener
-&removeEventListenersForType
-&removeEventListenersForTarget
-&removeCustomEventListeners
-&removeAllEventListeners
//删除指定监听器
void&removeEventListener(EventListener*&listener);
//删除某类型对应的所有监听器
//EventListener::Type::
// 单点触摸&:&TOUCH_ONE_BY_ONE
// 多点触摸&:&TOUCH_ALL_AT_ONCE
// 键盘&&&&&:&KEYBOARD
// 鼠标&&&&&:&MOUSE
// 加速计&&&:&ACCELERATION
// 自定义&&&:&CUSTOM
void&removeEventListenersForType(EventListener::Type&listenerType);
//删除绑定在节点target上的所有监听器
void&removeEventListenersForTarget(Node*&target,&bool&recursive&=&false);
//删除名字为customEventName的所有自定义监听器
void&removeCustomEventListeners(const&std::string&&customEventName);
//移除所有监听器
void&removeAllEventListeners();
&* 暂停、恢复在节点target上的所有监听器
-&pauseEventListenersForTarget
-&resumeEventListenersForTarget
void&pauseEventListenersForTarget(Node*&target,&bool&recursive&=&false);
void&resumeEventListenersForTarget(Node*&target,&bool&recursive&=&false);
-&setPriority
-&setEnabled
-&dispatchEvent
-&dispatchCustomEvent
//设置某监听器的优先级
void&setPriority(EventListener*&listener,&int&fixedPriority);
//启用事件分发器
void&setEnabled(bool&isEnabled);
bool&isEnabled()&
//手动派发自定义事件
void&dispatchEvent(Event*&event);
//给名字为eventName的自定义监听器,&绑定用户数据
void&dispatchCustomEvent(const&std::string&&eventName,&void&*optionalUserData&=&nullptr);
//4、关于事件监听器的优先权& & 通过 addEventListenerWithSceneGraphPriority 添加的监听器,优先权为0。&&&&通过&addEventListenerWithFixedPriority 添加的监听器,可以自定义优先权,但不能为0。&&&&&&优先级越低,越先响应事件。&&&&&&如果优先级相同,则上层的(z轴)先接收触摸事件。5、使用步骤&&&&(1)获取事件分发器 &:dispatcher =&Director::getInstance()-&getEventDispatcher();&&&&(2)创建监听器 & & &:auto listener =&EventListenerTouchOneByOne::create();&&&&(3)绑定响应事件函数:listener-&onTouchBegan =&CC_CALLBACK_2(callback, this);&&&&(4)将监听器添加到事件分发器dispatcher中:&&&&&&&&&&&&dispatcher-&addEventListenerWithSceneGraphPriority(Listener, this);&&&&(5)编写回调响应函数:&&&&&&&&&&&&bool callback(Touch* touch, Event* event) { ... }【触摸事件】1、单点触摸:EventListenerTouchOneByOne&&&&单点触摸监听器相关://
static&EventListenerTouchOneByOne*&create();
std::function&bool(Touch*,&Event*)&&onTouchB&//只有这个返回值为&bool
std::function&void(Touch*,&Event*)&&onTouchM
std::function&void(Touch*,&Event*)&&onTouchE
std::function&void(Touch*,&Event*)&&onTouchC
//&&&&使用举例://
//获取事件分发器
auto&dispatcher&=&Director::getInstance()-&getEventDispatcher();
//创建单点触摸监听器&EventListenerTouchOneByOne
auto&touchListener&=&EventListenerTouchOneByOne::create();
//单点触摸响应事件绑定
touchListener-&onTouchBegan&&&&&=&CC_CALLBACK_2(HelloWorld::onTouchBegan,&this);
touchListener-&onTouchMoved&&&&&=&CC_CALLBACK_2(HelloWorld::onTouchMoved,&this);
touchListener-&onTouchEnded&&&&&=&CC_CALLBACK_2(HelloWorld::onTouchEnded,&this);
touchListener-&onTouchCancelled&=&CC_CALLBACK_2(HelloWorld::onTouchCancelled,&this);
//在事件分发器中,添加触摸监听器,事件响应委托给&this&处理
dispatcher-&addEventListenerWithSceneGraphPriority(touchListener,&this);
//单点触摸事件响应函数
bool&onTouchBegan(Touch&*touch,&Event&*unused_event)&&&&&{&CCLOG("began");&return&&}
void&onTouchMoved(Touch&*touch,&Event&*unused_event)&&&&&{&CCLOG("moved");&}
void&onTouchEnded(Touch&*touch,&Event&*unused_event)&&&&&{&CCLOG("ended");&}
void&onTouchCancelled(Touch&*touch,&Event&*unused_event)&{&CCLOG("cancelled");&}
//2、多点触摸:EventListenerTouchAllAtOnce&&&&多点触摸监听器相关://
static&EventListenerTouchAllAtOnce*&create();
std::function&void(const&std::vector&Touch*&&,&Event*)&&onTouchesB
std::function&void(const&std::vector&Touch*&&,&Event*)&&onTouchesM
std::function&void(const&std::vector&Touch*&&,&Event*)&&onTouchesE
std::function&void(const&std::vector&Touch*&&,&Event*)&&onTouchesC
//&&&&使用举例://
//获取事件分发器
auto&dispatcher&=&Director::getInstance()-&getEventDispatcher();
//创建多点触摸监听器&EventListenerTouchAllAtOnce
auto&touchesListener&=&EventListenerTouchAllAtOnce::create();
//多点触摸响应事件绑定
touchesListener-&onTouchesBegan&&&&&=&CC_CALLBACK_2(HelloWorld::onTouchesBegan,&this);
touchesListener-&onTouchesMoved&&&&&=&CC_CALLBACK_2(HelloWorld::onTouchesMoved,&this);
touchesListener-&onTouchesEnded&&&&&=&CC_CALLBACK_2(HelloWorld::onTouchesEnded,&this);
touchesListener-&onTouchesCancelled&=&CC_CALLBACK_2(HelloWorld::onTouchesCancelled,&this);
//在事件分发器中,添加触摸监听器,事件响应委托给&this&处理
dispatcher-&addEventListenerWithSceneGraphPriority(touchesListener,&this);
//多点触摸事件响应函数
void&onTouchesBegan(const&std::vector&Touch*&&&touches,&Event&*unused_event)&&&&{&CCLOG("began");&}
void&onTouchesMoved(const&std::vector&Touch*&&&touches,&Event&*unused_event)&&&&{&CCLOG("moved");&}
void&onTouchesEnded(const&std::vector&Touch*&&&touches,&Event&*unused_event)&&&&{&CCLOG("ended");&}
void&onTouchesCancelled(const&std::vector&Touch*&&touches,&Event&*unused_event)&{&CCLOG("cancelled");&}
//【鼠标事件】&&&&EventListenerMouse,主要用于监听鼠标的点击、松开、移动、滚轮的事件。&&&&鼠标事件监听器相关://
static&EventListenerMouse*&create();
std::function&void(Event*&event)&&onMouseD& //按下鼠标,&单击鼠标
std::function&void(Event*&event)&&onMouseUp;& //松开鼠标,&按下的状态下松开
std::function&void(Event*&event)&&onMouseM //移动鼠标,&在屏幕中移动
std::function&void(Event*&event)&&onMouseS//滚动鼠标,&滚动鼠标的滚轮
//&&&&使用举例://
//获取事件分发器
auto&dispatcher&=&Director::getInstance()-&getEventDispatcher();
//创建鼠标事件监听器&EventListenerMouse
EventListenerMouse*&mouseListenter&=&EventListenerMouse::create();
//鼠标事件响应函数
mouseListenter-&onMouseDown&&&=&CC_CALLBACK_1(HelloWorld::onMouseDown,&&&this);
mouseListenter-&onMouseUp&&&&&=&CC_CALLBACK_1(HelloWorld::onMouseUp,&&&&&this);
mouseListenter-&onMouseMove&&&=&CC_CALLBACK_1(HelloWorld::onMouseMove,&&&this);
mouseListenter-&onMouseScroll&=&CC_CALLBACK_1(HelloWorld::onMouseScroll,&this);
//添加鼠标事件监听器,事件响应处理委托给this
dispatcher-&addEventListenerWithSceneGraphPriority(mouseListenter,&this);
//事件响应函数
void&onMouseDown(Event*&event)&&&{&CCLOG("Down");&}
void&onMouseUp(Event*&event)&&&&&{&CCLOG("UP");&}
void&onMouseMove(Event*&event)&&&{&CCLOG("MOVE");&}
void&onMouseScroll(Event*&event)&{&CCLOG("Scroll");&}
//【键盘事件】&&&&EventListenerKeyboard,主要用于监听键盘某个键的按下、松开的事件。&&&&键盘事件监听器相关://
static&EventListenerKeyboard*&create();
std::function&void(EventKeyboard::KeyCode,&Event*)&&onKeyP&&//按下某键
std::function&void(EventKeyboard::KeyCode,&Event*)&&onKeyR&//松开某键
//键盘按键枚举类型&EventKeyboard::KeyCode
//KeyCode的值对应的不是键盘的键值、也不是ASCII码,只是纯粹的枚举类型
// EventKeyboard::KeyCode::KEY_A
// EventKeyboard::KeyCode::KEY_1
// EventKeyboard::KeyCode::KEY_F1
// EventKeyboard::KeyCode::KEY_SPACE
// EventKeyboard::KeyCode::KEY_ALT
// EventKeyboard::KeyCode::KEY_SHIFT
//&&&&使用举例://
//获取事件分发器
auto&dispatcher&=&Director::getInstance()-&getEventDispatcher();
//创建键盘按键事件监听器
EventListenerKeyboard*&keyboardListener&=&EventListenerKeyboard::create();
//绑定事件响应函数
keyboardListener-&onKeyPressed&=&CC_CALLBACK_2(HelloWorld::onKeyPressed,&this);
keyboardListener-&onKeyReleased&=&CC_CALLBACK_2(HelloWorld::onKeyReleased,&this);
//添加监听器
dispatcher-&addEventListenerWithSceneGraphPriority(keyboardListener,&this);
//事件响应函数
void&onKeyPressed(EventKeyboard::KeyCode&keyCode,&Event*&event)&{
if&(EventKeyboard::KeyCode::KEY_J&==&keyCode)&{
CCLOG("Pressed:&J");
void&onKeyReleased(EventKeyboard::KeyCode&keyCode,&Event*&event)&{
if&(EventKeyboard::KeyCode::KEY_SPACE&==&keyCode)&{
CCLOG("Released:&SPACE");
//【加速计事件】&&&&EventListenerAcceleration,主要用于监听移动设备的所受重力方向感应事件。&&&&重力感应来自移动设备的加速计,通常支持 (X, Y, Z) 三个方向的加速度感应,所以又称为三向加速计。在实际应用中,可以根据3个方向的力度大小来计算手机倾斜的角度或方向。1、加速计信息类Acceleration&&&&该类中每个方向的加速度,大小都为一个重力加速度大小。//加速计信息
class&Acceleration
double&x;&double&y;&double&z;
//2、开启加速计感应&&&&在使用加速计事件监听器之前,需要先启用此硬件设备:&&&&&&&&Device::setAccelerometerEnabled(true);3、加速计监听器相关//
static&EventListenerAcceleration*&create(const&std::function&void(Acceleration*,&Event*)&&&callback);
std::function&void(Acceleration*,&Event*)&&onAccelerationE
//4、使用举例//
//标签:&显示加速计信息
label&=&Label::createWithTTF("no&used",&"Marker&Felt.ttf",&12);
label-&setPosition(visibleSize&/&2);
this-&addChild(label);
//小球:&可视化加速计
ball&=&Sprite::create("ball.png");
ball-&setPosition(visibleSize&/&2);
this-&addChild(ball);
//获取事件分发器
auto&dispatcher&=&Director::getInstance()-&getEventDispatcher();
//需要开启移动设备的加速计
Device::setAccelerometerEnabled(true);
//创建加速计事件监听器
auto&accelerationListener&=&EventListenerAcceleration::create(CC_CALLBACK_2(HelloWorld::onAccelerationEvent,&this));
//添加加速计监听器
dispatcher-&addEventListenerWithSceneGraphPriority(accelerationListener,&this);
//事件响应函数
void&HelloWorld::onAccelerationEvent(Acceleration*&acceleration,&Event*&event)
char&s[100];
sprintf(s,&"X:&%f;&Y:&%f;&Z:%f;&",&acceleration-&x,&acceleration-&y,&acceleration-&z);
label-&setString(s);
//改变小球ball的位置
float&x&=&ball-&getPositionX()&+&acceleration-&x&*&10;
float&y&=&ball-&getPositionY()&+&acceleration-&y&*&10;
Vec2&pos&=&Vec2(x,&y);
pos.clamp(ball-&getContentSize()&/&2,&Vec2(288,&512)&-&ball-&getContentSize()&/&2);
ball-&setPosition(pos);&//设置位置
//5、实际效果&&&&在电脑上看不出效果,需要移植到手机上,才能看到加速计的效果。650) this.width=650;" src="/wyfs02/M02/4B/61/wKioL1Qq6dCheq-6ABZS62wgGec329.gif" title="acc.gif" alt="wKioL1Qq6dCheq-6ABZS62wgGec329.gif" />【自定义事件】&&&&以上是系统自带的事件类型,事件由系统内部自动触发,如 触摸屏幕,键盘响应等。&&&&EventListenerCustom&自定义事件,它不是由系统自动触发,而是人为的干涉。&&&&它的出现,使得2.x中的 观察者模式 NotificationCenter(订阅发布消息)&被无情的遗弃了。&&&&在 3.x 中,使用EventListenerCustom来实现消息的订阅与发布。&&&&学习它之前,最好了解一下 NotificationCenter 这个类的用法。&&&&NotificationCenter 的用法参见: 1、创建自定义监听器&&&&该监听器,就相当于是订阅消息。即与NotificationCenter的 addObserver 类似。//
//eventName&:&监听器名字,即消息的名称
//callback&&:&监听器函数,即消息的回调函数
static&EventListenerCustom*&create(const&std::string&&eventName,&const&std::function&void(EventCustom*)&&&callback);
//&2、分发自定义事件&&&&自定义的事件监听器,需要通过手动的方式,将事件分发出去。& & & 通过&EventCustom(string eventName); & & &&来设置需要发布消息的数据信息,eventName为消息名称。&&&&&&&&其中EventCustom可以通过setUserData来绑定想要传递的消息数据。& & & 通过&dispatcher-&dispatchEvent(&event); 来手动将事件分发出去。即发布消息。&&&&&&&&这与NotificationCenter的 postNotification 类似。//
EventCustom&event("custom_event");
event-&setUserData((void*)123);&//&绑定消息传递的数据,可以为任意类型void。
dispatcher-&dispatchEvent(&event);&//&发布名称为"custom_event"的消息。
//3、使用举例//
//获取事件分发器
auto&dispatcher&=&Director::getInstance()-&getEventDispatcher();
//创建自定义事件监听器
//监听器名字&&:&"custom_event"
//事件响应函数:&HelloWorld::onCustomEvent
auto&customListener&=&EventListenerCustom::create("custom_event",&CC_CALLBACK_1(HelloWorld::onCustomEvent,&this));
//添加自定义事件监听器,优先权为1
dispatcher-&addEventListenerWithFixedPriority(customListener,&1);
//手动分发监听器的事件,通过dispatchEvent发布名称为custom_event的消息。
EventCustom&event&=&EventCustom("custom_event");
event-&setUserData((void*)123);&//&绑定消息传递的数据,可以为任意类型void。
dispatcher-&dispatchEvent(&event);
//消息事件回调函数
void&HelloWorld::onCustomEvent(EventCustom*&event)
//&获取消息传递的数据
int*&data&=&(int*)event-&getUserData()
CCLOG("onCustomEvent&data&=&%d",&data);
//4、说明& & & 每个自定义的事件监听器,都有一个监听器名字eventName。即为订阅的消息名称。& & & 需要通过&dispatcher-&dispatchEvent(&event); 来手动将事件分发出去。即为发布消息。&&&&& 可以通过 dispatcher-&dispatchCustomEvent(,); 来给自定义事件监听器绑定一个用户数据。【物理碰撞事件】&&&&有待研究。。。//
EventListenerPhysicsC
EventListenerPhysicsContactWithB
EventListenerPhysicsContactWithG
EventListenerPhysicsContactWithS
//【游戏手柄】&&&&有待研究。。。//
EventListenerC
//本文出自 “” 博客,请务必保留此出处
了这篇文章
类别:┆阅读(0)┆评论(0)当前位置: >
cocos2dx3.4 一 环境搭建
时间: 12:21
作者:wangjunshusheng
在官网下载cocos2dx3.4 和 cocos ide
方式一:VS创建项目
1、运行 cocos2dx3.4 下的setup.py
2、 在cocos2dx3.4 目录先创建Projects文件夹
3、在Projects下创建lua_test项目 cocos new lua_test -l lua
4、 在lua_test 的frameworks\runtime-src\proj.win32目录下运行lua_test.sln
方式二:cocos ide 方式
1 在cocoside的目录的窗口、首选项设置如下
创建lua_test
2 [LUA ERROR] [string "cocos/cocos2d/Cocos2dConstants.lua"]:620: attempt to index a nil value解决办法
把下面这段代码注释掉就行了
cc.AsyncTaskPool.TaskType = {
TASK_IO = 0,
TASK_NETWORK = 1,
TASK_OTHER = 2,
TASK_MAX_TYPE = 3,
或者在前面加上
cc.AsyncTaskPool = {}
常见问题参考链接:/bbs/read.php?tid=216602
下一篇:没有了Cocos2d-x环境搭建-W...
cocos.py newHelloCpp -p com.coco2dx.org -l cpp -d ~/Desktop创建了一个新项目(好像是复制了引擎了的很多文件),然后打开解决方案运行,又得要编译30分钟。我是想说3.4版本怎么像3.0那样用Python窗口直接创建运行。
python也是一样用这样的命令行来做。你可以考虑去下cocos完整集成框架。就会有一个自动创建的可视化工具。不过不推荐这么做。永久了你对这些命令行就都生疏了
Cocos2d-x环境搭建-W...
服务热线:400-678-82668139人阅读
cocos2dx(4)
首先,说一下android的canvas。
在android的canvas中,坐标系原点是在手机屏幕的左上角,所以,我们如果要设置一个图形在canvas中的位置的话可以通过设置这个图形的左上角那个点在canvas坐标系中的位置来,这个时候我们是以图形的左上角的那个点为锚点的即图形的xy坐标。比如要把一个边长为20的正方形放在屏幕的正中央,可以把x设为屏幕1/2宽的值,y为屏幕1/2高的值,这个时候,在视觉上的表现就是,正方形的左上角和屏幕的中心点重合了,而不是正方形的中点和屏幕中心点重合,之所以会这样就是因为我们用于决定正方形在canvas中位置的锚点是正方形的左上角的点而不是正方形的中点。在canvas这一套体系中我们是无法去把这个
锚点&从正方形的左上角移到正方形的中点的。
但是在cocos2d中我们可以很容易就做到这点,即可以把用来确定图形在父容器中位置的 锚点&移到图形内的任意位置。这样,我们通过setPosition来给图形设置位置的时候,实际上就相当于是让图形内的这个 锚点&和setPosition表示的在父容器中的位置点重合。比如,之前提到的正方形,如果想要正方形的中心点和屏幕的中心点重合,不用去改xy的值,只需要把这个 锚点&移到正方形的中点就可以了,这样当这个正方形被add到父容器(比如CCLayer)后就会把正方形放置在正方形中点和容器中点重合的位置了。
而这个 锚点&在图形内部的位置就是通过anchorPoint来指定的,anchorPoint的值为0-1,有两个方向的,x轴和y轴,在图形内部,是以左下角为坐标原点(opengl决定的)anchorPoint确定的点在图形内部坐标系中的坐标为
x=&anchorPoint.x*图形宽度
y=anchorPoint.y*图形高度
anchorPoint值为(0,1)表示基准点在图形的左上角。
anchorPoint值为(0.5,0.5)表示基准点在图形的中点,cocos2d中精灵默认就是这个值。
这里需要注意的是,position不由anchorPoint来决定,他是外部用来设置图形在父容器中所处的位置的,他不会因为anchorPoint的改变而改变,也就是说他跟anchorPoint实际上没多大关系,父容器会把图形的anchorPoint 锚点&放到position对应的点上以实现子元素的布局。
其实一句话就可以说清两者的关系。cocos2d会通过让图形(精灵)内anchorPoint对应的点和父容器(层)中position对应的点重合来确定精灵的位置。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:106085次
积分:1443
积分:1443
排名:千里之外
原创:37篇
评论:12条
(5)(2)(1)(2)(2)(3)(2)(3)(3)(1)(11)(4)(1)使用 Cocos2d-x 3.1.1 创建 Windows Phone 8 游戏开发环境 - 冠军 - 博客园
随笔 - 302
评论 - 1901
&cocos2d-x 是目前流行的游戏游戏开发框架,目前最新的版本是 3.1.1, 网上有些教程已经比较老了,本文将会介绍如何使用最新的 3.1.1 创建 Windows Phone 8 开发环境。
&本文假设你已经安装了 VS2012 或者 VS2013,并且已经安装了 Windows Phone8 的 SDK。
一、下载和安装 Cocos2d-x&
官网地址:
点击菜单栏中的 Download, 进入下载页面。
我们下载最新的 V3.1.1,新版功能会更多,但是可能会有一些新的 Bug 需要我们解决。
下载下来就是一个压缩包,
在磁盘上解压出来就是一个文件夹了。
到这里安装就已经结束了。
二、编译运行系统提供的测试程序
到文件夹 build 中,cocos2d-win32.vc2012 是 Windows 版的测试程序项目,cocos2d-wp8.vc2012 是 Windows Phone 版的测试程序项目。
首先看一看 windows 版的测试程序,注意,项目比较多,编译时间比较长。注意启动项目要设为 cpp-tests。
编译之后的运行效果。
&首先会调出来一个 Windows 安全的提示框,同意就可以了。
然后,就可以看到运行的界面。
然后再看一看 Windows Phone 版的测试程序。主程序的项目名称是 cpp-test (Winodws Phone 8.0) ,在 cpp-tests 文件夹中。
运行很正常,效果如下
三、使用 Cocos2d-console 创建项目
cocos2d 提供了使用命令行方式来创建和管理项目,这个工具称为 cocos2d-console, 位于文件夹 &tools\cocos2d-console 中。程序本身实际上保存在 bin 文件夹下。
这是工具是使用 python 脚本来实现的,所以,你要先在系统中安装 python, 官方网站:
现在有两个版本,一定要下载 2.7.7 版本。
下载之后,进行安装
选择安装路径。
选择安装内容,默认就可以
开始进入安装
Windows 8 还会弹出一个账号控制的提示。
确认之后,开始实际的安装。
稍等片刻,就会安装完毕。
安装之后,设置系统路径,默认会保存在 c:\Python27&下面。
然后,还要设置 cocos2d-console 的路径,可以与 python 一起完成。
首先,打开系统信息窗口。
点击高级系统设置
点击右下角的环境变量
如上图,选中 Path 之后,点击下面的编辑按钮。
这里需要注意的是,添加 Python 和 cocos2d-console 的路径,我这里是
;C:\Python27;D:\software\cocos2d-x-3.1.1\tools\cocos2d-console\
现在,可以打开一个命令行窗口检查一下了。
直接在命令和行输入 python 可以看到 python 的命令行提示,Ctrl+C 可以退出。
直接在命令行输入 cocos 可以看到 cocos-console 的帮助信息。
创建项目通过命令完成。
比如我们希望在 e:\cocos2d-projects 中创建,先在命令行下进入这个文件夹,输入命令 cocos 命令来创建,如下所示。
E:\cocos2d-projects&cocos new MyGame -l cpp
Runing command: new
& Copy template into E:\cocos2d-projects\MyGame
& Copying cocos2d-x files...
& Rename project name from 'HelloCpp' to 'MyGame'
& Replace the project name from 'HelloCpp' to 'MyGame'
& Replace the project package name from 'org.cocos2dx.hellocpp' to 'org.cocos2dx
.hellocpp'
E:\cocos2d-projects&
new 表示创建新项目,项目的名称为 MyGame
-l 用来配置语言 cpp 表示使用 CPP 语言
-p 表示包的路径
创建之后,会在当前文件夹下出现一个新的名为 MyGame 的文件夹,如下所示:
其中 proj.win32 就是 Win32 版,proj.wp8-xaml 就是 Windows Phone 版。
使用 Visual Studio 打开 MyGame 项目就可以编译,运行了。
但是 Windows Phone 版有一些问题。编译之后,应该会看到 6 个错误。
&仔细看一下错误信息,会发现是找不到文件的问题,这 6 个文件在项目 HelloCppComponent 中,都是引用了外部文件。
现在系统希望到 MyGame 下面的 cocos2d\cocos\2d\platform\wp8-xaml\cpp 文件夹下面找到文件,实际上到文件夹中看一下就会知道,cocos 下面就是 platform ,这个文件夹并不在 2d 文件夹下。所以造成了错误。
实际上,不仅这 6 个文件,还有对应的头文件都是这个问题,将这 12 个文件的引用路径修改一下就好了。
先选择文件,然后,在文件的属性窗口中修改路径。将多余的 2d 删除。
将所有 12 个路径修改之后,就可以了。

我要回帖

更多关于 cocos2dx 创建lua项目 的文章

 

随机推荐