Cocos2d-X中的粒子

前端之家收集整理的这篇文章主要介绍了Cocos2d-X中的粒子前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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)
		)
		);


执行结果:






原文链接:https://www.f2er.com/cocos2dx/346152.html

猜你在找的Cocos2d-x相关文章