cocos2d-x 问题汇总

在这里记录学习中遇到的问题

2013-4-9

学习http://mobile.51cto.com/iphone-330488.htm 精灵移动测试,但是编译时报错,查看错误日志,发现ccTime报错,百度之。

http://www.cocos2d-x.org/boards/6/topics/13072 这里面有讨论这个问题,原来ccTime被移除了,但是CCTime还是不好用,后来改为float 搞定

2013-4-10

教程用的cocos2d-x版本比较老,有些方法没有了

升级到cocos2d-x 2.0.2代码差异:

1、CCScene和CCLayer的初始化统一用create()函数进行创建。

//升级前代码CCScene *scene=NULL;do{        scene=CCScene::node();        CC_BREAK_IF(!scene);        GameScene *layer=GameScene:: node();        CC_BREAK_IF(!layer);    scene->addChild(layer);}while(0);
//升级后代码CCScene *scene=NULL;do{        scene=CCScene::create();        CC_BREAK_IF(!scene);        GameScene *layer=GameScene:: create();        CC_BREAK_IF(!layer);    scene->addChild(layer);}while(0);

2、取消了CCMutableArray,借用CCArray来代替

//升级前代码//定义CCMutableArray<cocos2d::CCSprite *> *GameScene::snakeSprites=NULL;//初始化snakeSprites=new CCMutableArray<CCSprite *>(len);//遍历for(int i=1;i<len;i++){    part=world->snake->parts->getObjectAtIndex(i);}
//升级后代码//定义CCArray* GameScene::snakeSprites = NULL;//初始化snakeSprites = new CCArray(len);//遍历for(int i=1;i<len;i++){    part=(SnakePart*)world->snake->parts->objectAtIndex(i);}

另外,CCArray可以通过CCARRAY_FOREACH来进行遍历;

CCArray* array1 = new CCArray();CCObject* arrayItem;CCARRAY_FOREACH(array1, arrayItem){    CCSprite* pItem = (CCSprite*)(arrayItem);}

3、cocos2d::ccTime统一用float进行代替。

//升级前代码void updateReady(cocos2d::ccTime dt);
//升级后代码void updateReady(float dt);

4、CCTouchDispatcher::sharedDispatcher()和CCDirector::sharedDirector()合并

//升级前代码CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this,kCCMenuTouchPriority,true);
//升级后代码CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, kCCMenuHandlerPriority, true);

5、一些get、set函数发生改变,比如setIsVisible变成setVisible,setIsTouchEnabled变成等setTouchEnabled等等;

//升级前代码snakeSprite->setIsVisible(isVisible);this->setIsTouchEnabled(true);
//升级后代码snakeSprite->setVisible(isVisible);this->setTouchEnabled(true);

其它的改变在使用过程中如果再遇到再继续添加。

 2013-4-11

那个教程太老了,继续更新修改的地方

error C2039: 'view' : is not a member of 'cocos2d::CCTouch'
分析:源码中的CCPoint location = touch->locationInView(touch->view());这一句过时了。修改为:
CCPoint location = touch->getLocationInView();

CCDirector::getSharedDirector()改为CCDirector::sharedDirector()

CGSize 改为CCSize (遇到cg的出错就改为cc试试)

这样改完子弹就能发射啦~~~


2013-10-7

设置背景 cocos2d-x默认是横屏的 Android下改为竖屏  只能显示一般 需要修改一下代码才正常

background1->setAnchorPoint(ccp(-0.5f,0));   原因未知

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值