您的位置:首页 >> Cocos2d-x >> 和屌丝一起学cocos2dx-粒子特效

和屌丝一起学cocos2dx-粒子特效

[ 孤狼 | 2015-02-09 17:25:05 | Cocos2d-x | 2445°C | 0条评论 ]
声 明

本教程仅用于初学cocos2dx同学使用,内容由本人(孤狼)学习过程中笔记编写,本教程使用cocos2dx版本为2.1.4。本教程内容可以自由转载,但必须同时附带本声明,或注明出处。
gl.paea.cn版权所有。


       Hello,大家好,欢迎回到“和屌丝一起学coocs2dx”系列教程,这两天有事,就停更了两天。好了,上节我们说到了“数据存储”,大家一定都做出来了吧。是不是很简单呢?还有哦,数据存储直接存是明码的哦,你可以对数据加密,加密方式有很多,你可以去网上百度一下,自己选一种方式。好了,这节我们来说一下一个很炫的功能-粒子特效。


【一】:干嘛的


粒子特效是用来增加游戏体验感的。比如下雪啦,爆炸啦等等。


【二】:函数


1.特效

CCParticleExplosion        //爆炸粒子特效

CCParticleFire                  //火焰粒子特效

CCParticleFlower             //花束粒子特效

CCParticleFireworks       //烟花粒子特效

CCParticleGalaxy            //星系粒子特效

CCParticleMeteor           //流星粒子特效

CCParticleRain                //下雨粒子特效

CCParticleSmoke            //烟雾粒子特效

CCParticleSnow              //下雪粒子特效

CCParticleSpiral              //漩涡粒子特效

CCParticleSun                 //太阳粒子特效


2.函数

setTexture();

   //设置特效贴图。这里注意。老版本中如果不设置这项会报错退出。2.1.4中不设置可以使用。

setAutoRemoveOnFinish(bool);

   //设置自动释放true为自动释放。

setPositionType()

   //设置移动类型

   kCCPositionTypeFree//自由模式。粒子不予发射器联系,发射后粒子走自己的轨道,可以做出焰尾。

   kCCPositionTypeRelative//相对模式。粒子发射器随节点移动而移动。

   kCCPositionTypeGrouped//相对模式。粒子随发射器移动而移动。


3.自定义

CCParticleSystemQuad::create();

这个函数是用来加载自定义的plist文件的。怎么自定义呢?我们使用工具“红孩儿工具箱”就能做自定义特效了。



【三】:示例


1.新建一个项目:Particledemo

2.载入一张很小的图片用来做贴图。


Particledemo.cpp


//-new-//

CCSize mysize=CCDirector::sharedDirector()->getWinSize();

////CCParticleExplosion特效

////创建CCParticleExplosion特效

//CCParticleSystem * p1=CCParticleExplosion::create();

////设置特效贴图

//p1->setTexture(CCTextureCache::sharedTextureCache()->addImage("t.jpg"));

////设置自动释放

//p1->setAutoRemoveOnFinish(true);

////设置移动类型

//p1->setPositionType(kCCPositionTypeGrouped);

////设置位置

//p1->setPosition(ccp(mysize.width/2,mysize.height/2));

////添加特效

//this->addChild(p1);


////CCParticleExplosion特效

//CCParticleSystem * p2=CCParticleFire::create();

//p2->setTexture(CCTextureCache::sharedTextureCache()->addImage("t.jpg"));

//p2->setAutoRemoveOnFinish(true);

//this->addChild(p2);


////CCParticleFlower特效

//CCParticleSystem * p3=CCParticleFlower::create();

////p3->setTexture(CCTextureCache::sharedTextureCache()->addImage("t.jpg"));

//p3->setAutoRemoveOnFinish(true);

//this->addChild(p3);


////CCParticleFireworks特效

//CCParticleSystem * p4=CCParticleFireworks::create();

////p4->setTexture(CCTextureCache::sharedTextureCache()->addImage("t.jpg"));

//p4->setAutoRemoveOnFinish(true);

//this->addChild(p4);


////CCParticleGalaxy特效

//CCParticleSystem * p5=CCParticleGalaxy::create();

////p5->setTexture(CCTextureCache::sharedTextureCache()->addImage("t.jpg"));

//p5->setAutoRemoveOnFinish(true);

//this->addChild(p5);


////CCParticleMeteor特效

//CCParticleSystem * p6=CCParticleMeteor::create();

////p6->setTexture(CCTextureCache::sharedTextureCache()->addImage("t.jpg"));

//p6->setAutoRemoveOnFinish(true);

//this->addChild(p6);


////CCParticleRain特效

//CCParticleSystem * p7=CCParticleRain::create();

////p7->setTexture(CCTextureCache::sharedTextureCache()->addImage("t.jpg"));

//p7->setAutoRemoveOnFinish(true);

//this->addChild(p7);


////CCParticleSmoke特效

//CCParticleSystem * p8=CCParticleSmoke::create();

////p8->setTexture(CCTextureCache::sharedTextureCache()->addImage("t.jpg"));

//p8->setAutoRemoveOnFinish(true);

//this->addChild(p8);


////CCParticleSnow特效

//CCParticleSystem * p9=CCParticleSnow::create();

////p9->setTexture(CCTextureCache::sharedTextureCache()->addImage("t.jpg"));

//p9->setAutoRemoveOnFinish(true);

//this->addChild(p9);


////CCParticleSpiral特效

//CCParticleSystem * p10=CCParticleSpiral::create();

////p10->setTexture(CCTextureCache::sharedTextureCache()->addImage("t.jpg"));

//p10->setAutoRemoveOnFinish(true);

//this->addChild(p10);


////CCParticleSun特效

//CCParticleSystem * p11=CCParticleSun::create();

////p11->setTexture(CCTextureCache::sharedTextureCache()->addImage("t.jpg"));

//p11->setAutoRemoveOnFinish(true);

//this->addChild(p11);


//自定义特效

CCParticleSystem * mypat=CCParticleSystemQuad::create("1.plist");

mypat->setPosition(ccp(mysize.width/2,mysize.height/2));

this->addChild(mypat);

//-new-//



好了,我们来看看效果吧。



本节DEMO下载


转载请注明出处:http://gl.paea.cn/n.php?n=32
 
如您看得高兴,欢迎随意投喂,让我们坚持创作!
赞赏一个鸡腿
还没有人留下遗迹
综合 · 搜索