cocos2d

来源:互联网 发布:中国早期网络漫画 编辑:程序博客网 时间:2024/06/13 05:00

这一章中,我们来介绍下粒子系统,通过粒子,我们可以实现很酷的效果,特效等。OK,还是直接上代码:

 cocos2d::CCParticleSystemQuad *particle;        particle=CCParticleSystemQuad::create("comet.plist");        particle->setPosition(ccp(100, 200));        this->addChild(particle, 1);

CCParticleSystemQuad,矩形粒子,点粒子CCParticleSystemPoint应该是没了,这里我都是通过粒子编辑器直接生成了plist文件,通过加载plist来创建粒子,是不是很方便。。。^_^,OK,看效果图

现在,我们换个粒子,通过触摸点来移动它看看:

首先开启触摸

this->setTouchEnabled(true);

然后重写touchmove事件

void HelloWorld::ccTouchesMoved(CCSet *touchs, CCEvent *event){    //获取触点指针容器中第一个元素    CCSetIterator it=touchs->begin();    //将其转化为触点信息    CCTouch *touch=(CCTouch *)(*it);        CCPoint touchLocation=touch->getLocation();          //  touchLocation=CCDirector::sharedDirector()->convertToGL(touchLocation);                particle->setPosition(ccp(touchLocation.x, touchLocation.y));    }

OK,就这么简单,看效果图:

 


<script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* cnblogs 首页横幅 */google_ad_slot = "5419468456";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>