现在的位置: 首页 > 综合 > 正文

cocos2d

2013年10月25日 ⁄ 综合 ⁄ 共 729字 ⁄ 字号 评论关闭

这一章中,我们来介绍下粒子系统,通过粒子,我们可以实现很酷的效果,特效等。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,就这么简单,看效果图:

 

【上篇】
【下篇】

抱歉!评论已关闭.