Cocos2d-x   发布时间:2022-05-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了【Cocos2d-X(2.x) 游戏开发系列之一】cocos2dx(v2.x)与(v1.x)的一些常用函数区别讲解!在2.x版CCFileData类被去除等大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

cocos2dx v2.0版本发布一段时间了,现在最新版本是cocos2d-2.0-rc2-x-2.0.1 ;这段时间Himi对2.x的更新版也有关注,也尝试使用过,发现不少地方都有改动,对于Himi最新项目快到尾声的虑,所以也没有更新引擎到最新。那么@R_944_10693@Himi将陆续使用最新v2.x版本的一些东东,同步更新一些经常使用的改动以及值得注意的地方发博文出来与大家共享;

在之前我们使用COcos2dx 1.x版本中,我们都知道,创建一个CCObject类,都是类名然后::类名去除CC这个规律来创建和初始化,但是这一条在Cocos2dx 2.x版本就不行了,在cocos2dx 2.x版本中初始化和创建类基本都是 create 关键字开头创建。

首先我们来看第一个改动: CCLayer初始化

自定义Layer,类名:World

.h中:
1.x版本Layer函数
LAYER_NODE_FUNC(World);

2.x版本Layer函数
LAYER_CREATE_FUNC(World);
.cpp中:
1.x版本的重写函数:

CCScene* World::scene()
{
  CCScene *scene = CCScene::node(); 
  World *layer = World::node(); 
  scene->addChild(layer); 
  return scene;
}

2.x版本的重写函数:

CCScene* World::scene()
{
  CCScene *scene = CCScene::create(); 
  World *layer = World::create(); 
  scene->addChild(layer); 
  return scene;
}

然后我们看第二个常用的CCArray的初始化:

1.x版本的CCArray创建: 
CCArray*array = CCArray::array();

2.x版本的CCArray创建:  
CCArray*array = CCArray::create();

第三个我们看文件路径相关CCFileUtils函数使用:

1.x版本的使用: 
const char* fullpath = cocos2d::CCFileUtils::fullPathFromRelativePath(patha.c_str());

2.x版本的使用:
const char* fullpath = cocos2d::CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(patha.c_str());

第四个精灵的创建:

1.x中精灵的创建:
 CCSprite *sp = CCSprite::spriteWithFile("himi.png");
2.x中精灵的创建:
 CCSprite *sp = CCSprite::create("himi.png");

第五个注册触屏事件监听

1.x中注册:
CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this,0,falsE);

2.x中注册:
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,falsE);

第六个粒子相关

1.x粒子创建和设置自动释放设置
CCParticleSystem *tempSystem =  CCParticleSystem::particleWithFile("himi.plist");
        tempSystem->setIsAutoRemoveOnFinish@R_696_6334@;
        
2.x粒子创建和设置自动释放设置        
CCParticleSystem *tempSystem =  CCParticleSystemQuad::create("himi.plist");
        tempSystem->setAutoRemoveOnFinish@R_696_6334@;

第七个:CCFileData 类去除了:

1.x的CCFileData的使用:
     
cocos2d::CCFileData fileDataClip(const char *pszFilename,const char *pszModE);
 
2.x中CCFileData被删除,直接使用如下函数即可代替:
CCFileUtils::sharedFileUtils()->getFileData(const char *pszFilename,const char *pszMode,unsigned long *pSizE)

第八个Action 动作使用与创建:

1.x动作的创建与使用:
this->runAction(CCSequence::actions(
                                            CCMoveTo::actionWithDuration(ccpDistance(this->getPosition(),target) / velocity,target),CCCallFunc::actionWithTarget(this,callfunc_SELEctor(Player::removeTarget)),NULL));
 
2.x的动作创建和使用:      
this->runAction(CCSequence::create(
                                           CCMoveTo::create(ccpDistance(this->getPosition(),CCCallFunc::create(this,NULL));

大佬总结

以上是大佬教程为你收集整理的【Cocos2d-X(2.x) 游戏开发系列之一】cocos2dx(v2.x)与(v1.x)的一些常用函数区别讲解!在2.x版CCFileData类被去除等全部内容,希望文章能够帮你解决【Cocos2d-X(2.x) 游戏开发系列之一】cocos2dx(v2.x)与(v1.x)的一些常用函数区别讲解!在2.x版CCFileData类被去除等所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。