Cocos2d-x引擎提供了强大的,它在模仿自然现象、物理现象及空间扭曲上具备得天独厚的优势,为我们实现一些真实自然而又带有随机性的特效(如爆炸、烟花、水流)提供了方便

程序实例1:创建一个烟花效果的方法1

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

    //烟花效果
CCParticleFireworks* fw = CCParticleFireworks::create();
addChild(fw); fw->setPosition(ccp(winSize.width / 2, winSize.height / 2));

运行结果:

Cocos2d-X中的粒子-LMLPHP

程序实例2:创建一个烟花效果的方法2

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

    //烟花效果
CCParticleSystemQuad* p = CCParticleFireworks::create();
addChild(p); p->setPosition(winSize.width / 2, winSize.height / 2);

运行结果:

Cocos2d-X中的粒子-LMLPHP

程序实例3:创建一个星云效果

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

      //星云效果
CCParticleSystemQuad* p2 = CCParticleGalaxy::create();
addChild(p2); p2->setPosition(ccp(winSize.width / 2, winSize.height / 2));

运行结果:

Cocos2d-X中的粒子-LMLPHP

程序实例4:创建一个彗星效果

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

	 //彗星效果
CCParticleSystemQuad* p2 = CCParticleMeteor::create();
addChild(p2); p2->setPosition(ccp(winSize.width / 2, winSize.height / 2));

运行结果:

Cocos2d-X中的粒子-LMLPHP

程序实例5:创建一个花束效果

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

	//鲜花效果
CCParticleSystemQuad* p2 = CCParticleFlower::create();
addChild(p2); p2->setPosition(ccp(winSize.width / 2, winSize.height / 2));

运行结果:

Cocos2d-X中的粒子-LMLPHP

程序实例6:创建一个火焰效果

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

	 //火焰效果
CCParticleSystemQuad* p2 = CCParticleFire::create();
addChild(p2); p2->setPosition(ccp(winSize.width / 2, winSize.height / 2));

运行结果:

Cocos2d-X中的粒子-LMLPHP

程序实例7:5个效果放在一起展示

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

    //烟花效果
CCParticleSystemQuad* p1 = CCParticleFireworks::create(); //星云效果
CCParticleSystemQuad* p2 = CCParticleGalaxy::create(); //火焰效果
CCParticleSystemQuad* p3 = CCParticleFire::create(); //彗星效果
CCParticleSystemQuad* p4 = CCParticleMeteor::create(); //鲜花效果
CCParticleSystemQuad* p5 = CCParticleFlower::create(); addChild(p1);
addChild(p2);
addChild(p3);
addChild(p4);
addChild(p5); p1->setPosition(ccp(100, winSize.height / 2));
p2->setPosition(ccp(200, winSize.height / 2));
p3->setPosition(ccp(300, winSize.height / 2));
p4->setPosition(ccp(400, winSize.height / 2));
p5->setPosition(ccp(500, winSize.height / 2));

运行效果:

Cocos2d-X中的粒子-LMLPHP

程序实例8:运行人工编辑的粒子

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

    CCParticleSystemQuad* p = CCParticleSystemQuad::create("Particles/Galaxy.plist");
addChild(p); p->setPosition(ccp(winSize.width / 2, winSize.height / 2));

运行结果:

Cocos2d-X中的粒子-LMLPHP

程序实例8:运行能够移动的粒子

 CCLayer::init();

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

    CCParticleSystemQuad* p = CCParticleSystemQuad::create("Particles/Flower.plist");
addChild(p);
p->setPosition(ccp(100, winSize.height / 2)); CCMoveBy* by = CCMoveBy::create(4, ccp(winSize.width, 0)); p->runAction(
CCRepeatForever::create(
CCSequence::create(by, by->reverse(), NULL)
)
);

运行结果:

Cocos2d-X中的粒子-LMLPHP





05-26 16:36