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

Cocos2d-X中的粒子

时间:2017-05-01 13:39:06      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:director   ref   ast   net   ddc   log   position   init   art   

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


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

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

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

运行结果:

技术分享


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

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

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

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


运行结果:
技术分享


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

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

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

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


运行结果:

技术分享


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

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

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

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

运行结果:
技术分享


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

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

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

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

运行结果:
技术分享


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

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

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

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

运行结果:

技术分享


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

运行效果:

技术分享


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

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

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

运行结果:

技术分享


程序实例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中的粒子

标签:director   ref   ast   net   ddc   log   position   init   art   

原文地址:http://www.cnblogs.com/yutingliuyl/p/6791678.html

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