码迷,mamicode.com
首页 > 其他好文 > 详细

Cocos2d-X中的粒子

时间:2014-11-16 18:46:35      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   ar   os   sp   for   

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


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

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

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

执行结果:

bubuko.com,布布扣


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

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

    
    //烟花效果
   	CCParticleSystemQuad* p = CCParticleFireworks::create();
    addChild(p);

    p->setPosition(winSize.width / 2, winSize.height / 2);


执行结果:
bubuko.com,布布扣


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

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

      //星云效果
	CCParticleSystemQuad* p2 = CCParticleGalaxy::create();
    addChild(p2);

    p2->setPosition(ccp(winSize.width / 2, winSize.height / 2));


执行结果:

bubuko.com,布布扣


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

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

	 //彗星效果
	CCParticleSystemQuad* p2 = CCParticleMeteor::create();
    addChild(p2);

    p2->setPosition(ccp(winSize.width / 2, winSize.height / 2));

执行结果:
bubuko.com,布布扣


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

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

	//鲜花效果
    CCParticleSystemQuad* p2 = CCParticleFlower::create();
    addChild(p2);

    p2->setPosition(ccp(winSize.width / 2, winSize.height / 2));

执行结果:
bubuko.com,布布扣


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

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

	 //火焰效果
	CCParticleSystemQuad* p2 = CCParticleFire::create();
    addChild(p2);

    p2->setPosition(ccp(winSize.width / 2, winSize.height / 2));

执行结果:

bubuko.com,布布扣


程序实例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));

执行效果:

bubuko.com,布布扣


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

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

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

执行结果:

bubuko.com,布布扣


程序实例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)
		)
		);


执行结果:

bubuko.com,布布扣






Cocos2d-X中的粒子

标签:style   blog   http   io   color   ar   os   sp   for   

原文地址:http://blog.csdn.net/u010105970/article/details/41171259

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!