2012-04-04 21:58:04 +08:00
|
|
|
#include "ParticleTest.h"
|
|
|
|
// #include "CCActionInterval.h"
|
|
|
|
// #include "CCMenu.h"
|
|
|
|
// #include "CCLabelTTF.h"
|
|
|
|
// #include "CCLabelAtlas.h"
|
|
|
|
// #include "touch_dispatcher/CCTouchDispatcher.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
/*#include "support/CCPointExtension.h"*/
|
|
|
|
|
|
|
|
enum {
|
2012-04-19 14:35:52 +08:00
|
|
|
kTagParticleCount = 1,
|
2012-04-04 21:58:04 +08:00
|
|
|
};
|
|
|
|
|
2011-07-08 15:57:46 +08:00
|
|
|
CCLayer* nextParticleAction();
|
|
|
|
CCLayer* backParticleAction();
|
2012-04-04 21:58:04 +08:00
|
|
|
CCLayer* restartParticleAction();
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoFirework
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoFirework::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
m_emitter = CCParticleFireworks::create();
|
2010-09-13 18:07:12 +08:00
|
|
|
m_emitter->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
m_background->addChild(m_emitter, 10);
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_stars1) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
std::string DemoFirework::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ParticleFireworks";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoFire
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoFire::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
m_emitter = CCParticleFire::create();
|
2010-09-13 18:07:12 +08:00
|
|
|
m_emitter->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
m_background->addChild(m_emitter, 10);
|
|
|
|
|
|
|
|
m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) );//.pvr");
|
|
|
|
CCPoint p = m_emitter->getPosition();
|
2012-10-23 17:48:50 +08:00
|
|
|
m_emitter->setPosition( ccp(p.x, 100) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
std::string DemoFire::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ParticleFire";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoSun
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoSun::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
m_emitter = CCParticleSun::create();
|
2010-09-13 18:07:12 +08:00
|
|
|
m_emitter->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
m_background->addChild(m_emitter, 10);
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) );
|
|
|
|
|
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
std::string DemoSun::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ParticleSun";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoGalaxy
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoGalaxy::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
m_emitter = CCParticleGalaxy::create();
|
2010-09-13 18:07:12 +08:00
|
|
|
m_emitter->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
m_background->addChild(m_emitter, 10);
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
std::string DemoGalaxy::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ParticleGalaxy";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoFlower
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoFlower::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
m_emitter = CCParticleFlower::create();
|
2010-09-13 18:07:12 +08:00
|
|
|
m_emitter->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
m_background->addChild(m_emitter, 10);
|
2010-08-23 16:38:10 +08:00
|
|
|
m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_stars1) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
std::string DemoFlower::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ParticleFlower";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoBigFlower
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoBigFlower::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_emitter = new CCParticleSystemQuad();
|
|
|
|
m_emitter->initWithTotalParticles(50);
|
|
|
|
//m_emitter->autorelease();
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_background->addChild(m_emitter, 10);
|
|
|
|
////m_emitter->release(); // win32 : use this line or remove this line and use autorelease()
|
2010-08-25 11:37:22 +08:00
|
|
|
m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_stars1) );
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_emitter->setDuration(-1);
|
|
|
|
|
|
|
|
// gravity
|
|
|
|
m_emitter->setGravity(CCPointZero);
|
|
|
|
|
|
|
|
// angle
|
|
|
|
m_emitter->setAngle(90);
|
|
|
|
m_emitter->setAngleVar(360);
|
|
|
|
|
|
|
|
// speed of particles
|
|
|
|
m_emitter->setSpeed(160);
|
|
|
|
m_emitter->setSpeedVar(20);
|
|
|
|
|
|
|
|
// radial
|
|
|
|
m_emitter->setRadialAccel(-120);
|
|
|
|
m_emitter->setRadialAccelVar(0);
|
|
|
|
|
|
|
|
// tagential
|
|
|
|
m_emitter->setTangentialAccel(30);
|
|
|
|
m_emitter->setTangentialAccelVar(0);
|
|
|
|
|
|
|
|
// emitter position
|
2012-10-23 17:48:50 +08:00
|
|
|
m_emitter->setPosition( ccp(160,240) );
|
2012-04-19 14:35:52 +08:00
|
|
|
m_emitter->setPosVar(CCPointZero);
|
|
|
|
|
|
|
|
// life of particles
|
|
|
|
m_emitter->setLife(4);
|
|
|
|
m_emitter->setLifeVar(1);
|
|
|
|
|
|
|
|
// spin of particles
|
|
|
|
m_emitter->setStartSpin(0);
|
|
|
|
m_emitter->setStartSizeVar(0);
|
|
|
|
m_emitter->setEndSpin(0);
|
|
|
|
m_emitter->setEndSpinVar(0);
|
|
|
|
|
|
|
|
// color of particles
|
|
|
|
ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f};
|
|
|
|
m_emitter->setStartColor(startColor);
|
|
|
|
|
|
|
|
ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f};
|
|
|
|
m_emitter->setStartColorVar(startColorVar);
|
|
|
|
|
|
|
|
ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f};
|
|
|
|
m_emitter->setEndColor(endColor);
|
|
|
|
|
|
|
|
ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f};
|
|
|
|
m_emitter->setEndColorVar(endColorVar);
|
|
|
|
|
|
|
|
// size, in pixels
|
|
|
|
m_emitter->setStartSize(80.0f);
|
|
|
|
m_emitter->setStartSizeVar(40.0f);
|
|
|
|
m_emitter->setEndSize(kParticleStartSizeEqualToEndSize);
|
|
|
|
|
|
|
|
// emits per second
|
|
|
|
m_emitter->setEmissionRate(m_emitter->getTotalParticles()/m_emitter->getLife());
|
|
|
|
|
|
|
|
// additive
|
2012-06-15 15:10:40 +08:00
|
|
|
m_emitter->setBlendAdditive(true);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
std::string DemoBigFlower::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ParticleBigFlower";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoRotFlower
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoRotFlower::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
|
|
|
|
|
|
|
m_emitter = new CCParticleSystemQuad();
|
|
|
|
m_emitter->initWithTotalParticles(300);
|
|
|
|
//m_emitter->autorelease();
|
|
|
|
|
|
|
|
m_background->addChild(m_emitter, 10);
|
|
|
|
////m_emitter->release(); // win32 : Remove this line
|
|
|
|
m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_stars2) );
|
|
|
|
|
|
|
|
// duration
|
|
|
|
m_emitter->setDuration(-1);
|
|
|
|
|
|
|
|
// gravity
|
|
|
|
m_emitter->setGravity(CCPointZero);
|
|
|
|
|
|
|
|
// angle
|
|
|
|
m_emitter->setAngle(90);
|
|
|
|
m_emitter->setAngleVar(360);
|
|
|
|
|
|
|
|
// speed of particles
|
|
|
|
m_emitter->setSpeed(160);
|
|
|
|
m_emitter->setSpeedVar(20);
|
|
|
|
|
|
|
|
// radial
|
|
|
|
m_emitter->setRadialAccel(-120);
|
|
|
|
m_emitter->setRadialAccelVar(0);
|
|
|
|
|
|
|
|
// tagential
|
|
|
|
m_emitter->setTangentialAccel(30);
|
|
|
|
m_emitter->setTangentialAccelVar(0);
|
|
|
|
|
|
|
|
// emitter position
|
2012-10-23 17:48:50 +08:00
|
|
|
m_emitter->setPosition( ccp(160,240) );
|
2012-04-19 14:35:52 +08:00
|
|
|
m_emitter->setPosVar(CCPointZero);
|
|
|
|
|
|
|
|
// life of particles
|
|
|
|
m_emitter->setLife(3);
|
|
|
|
m_emitter->setLifeVar(1);
|
|
|
|
|
|
|
|
// spin of particles
|
|
|
|
m_emitter->setStartSpin(0);
|
|
|
|
m_emitter->setStartSpinVar(0);
|
|
|
|
m_emitter->setEndSpin(0);
|
|
|
|
m_emitter->setEndSpinVar(2000);
|
|
|
|
|
|
|
|
// color of particles
|
|
|
|
ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f};
|
|
|
|
m_emitter->setStartColor(startColor);
|
|
|
|
|
|
|
|
ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f};
|
|
|
|
m_emitter->setStartColorVar(startColorVar);
|
|
|
|
|
|
|
|
ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f};
|
|
|
|
m_emitter->setEndColor(endColor);
|
|
|
|
|
|
|
|
ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f};
|
|
|
|
m_emitter->setEndColorVar(endColorVar);
|
|
|
|
|
|
|
|
// size, in pixels
|
|
|
|
m_emitter->setStartSize(30.0f);
|
|
|
|
m_emitter->setStartSizeVar(00.0f);
|
|
|
|
m_emitter->setEndSize(kParticleStartSizeEqualToEndSize);
|
|
|
|
|
|
|
|
// emits per second
|
|
|
|
m_emitter->setEmissionRate(m_emitter->getTotalParticles()/m_emitter->getLife());
|
|
|
|
|
|
|
|
// additive
|
2012-06-15 15:10:40 +08:00
|
|
|
m_emitter->setBlendAdditive(false);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
std::string DemoRotFlower::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ParticleRotFlower";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoMeteor
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoMeteor::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
m_emitter = CCParticleMeteor::create();
|
2010-09-13 18:07:12 +08:00
|
|
|
m_emitter->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
m_background->addChild(m_emitter, 10);
|
|
|
|
|
|
|
|
m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) );
|
|
|
|
|
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
std::string DemoMeteor::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ParticleMeteor";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoSpiral
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoSpiral::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
m_emitter = CCParticleSpiral::create();
|
2010-09-13 18:07:12 +08:00
|
|
|
m_emitter->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
m_background->addChild(m_emitter, 10);
|
|
|
|
|
|
|
|
m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) );
|
|
|
|
|
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
std::string DemoSpiral::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ParticleSpiral";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoExplosion
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoExplosion::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
m_emitter = CCParticleExplosion::create();
|
2010-09-13 18:07:12 +08:00
|
|
|
m_emitter->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
m_background->addChild(m_emitter, 10);
|
|
|
|
|
|
|
|
m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_stars1) );
|
|
|
|
|
2012-06-15 16:47:30 +08:00
|
|
|
m_emitter->setAutoRemoveOnFinish(true);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
std::string DemoExplosion::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ParticleExplosion";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoSmoke
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoSmoke::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
m_emitter = CCParticleSmoke::create();
|
2010-09-13 18:07:12 +08:00
|
|
|
m_emitter->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
m_background->addChild(m_emitter, 10);
|
2010-09-07 16:05:18 +08:00
|
|
|
m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
CCPoint p = m_emitter->getPosition();
|
2012-10-23 17:48:50 +08:00
|
|
|
m_emitter->setPosition( ccp( p.x, 100) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
std::string DemoSmoke::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ParticleSmoke";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoSnow
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoSnow::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
m_emitter = CCParticleSnow::create();
|
2010-09-13 18:07:12 +08:00
|
|
|
m_emitter->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
m_background->addChild(m_emitter, 10);
|
|
|
|
|
|
|
|
CCPoint p = m_emitter->getPosition();
|
2012-10-23 17:48:50 +08:00
|
|
|
m_emitter->setPosition( ccp( p.x, p.y-110) );
|
2012-04-19 14:35:52 +08:00
|
|
|
m_emitter->setLife(3);
|
|
|
|
m_emitter->setLifeVar(1);
|
|
|
|
|
|
|
|
// gravity
|
2012-10-23 17:48:50 +08:00
|
|
|
m_emitter->setGravity(ccp(0,-10));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// speed of particles
|
|
|
|
m_emitter->setSpeed(130);
|
|
|
|
m_emitter->setSpeedVar(30);
|
|
|
|
|
|
|
|
|
|
|
|
ccColor4F startColor = m_emitter->getStartColor();
|
|
|
|
startColor.r = 0.9f;
|
|
|
|
startColor.g = 0.9f;
|
|
|
|
startColor.b = 0.9f;
|
|
|
|
m_emitter->setStartColor(startColor);
|
|
|
|
|
|
|
|
ccColor4F startColorVar = m_emitter->getStartColorVar();
|
|
|
|
startColorVar.b = 0.1f;
|
|
|
|
m_emitter->setStartColorVar(startColorVar);
|
|
|
|
|
|
|
|
m_emitter->setEmissionRate(m_emitter->getTotalParticles()/m_emitter->getLife());
|
|
|
|
|
|
|
|
m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_snow) );
|
|
|
|
|
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
std::string DemoSnow::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ParticleSnow";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoRain
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoRain::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
m_emitter = CCParticleRain::create();
|
2010-09-13 18:07:12 +08:00
|
|
|
m_emitter->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
m_background->addChild(m_emitter, 10);
|
|
|
|
|
|
|
|
CCPoint p = m_emitter->getPosition();
|
2012-10-23 17:48:50 +08:00
|
|
|
m_emitter->setPosition( ccp( p.x, p.y-100) );
|
2012-04-19 14:35:52 +08:00
|
|
|
m_emitter->setLife(4);
|
|
|
|
|
|
|
|
m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) );
|
|
|
|
|
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
std::string DemoRain::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ParticleRain";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoModernArt
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoModernArt::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2011-12-01 12:04:43 +08:00
|
|
|
//FIXME: If use CCParticleSystemPoint, bada 1.0 device will crash.
|
|
|
|
// Crash place: CCParticleSystemPoint.cpp Line 149, function: glDrawArrays(GL_POINTS, 0, m_uParticleIdx);
|
|
|
|
// m_emitter = new CCParticleSystemPoint();
|
|
|
|
m_emitter = new CCParticleSystemQuad();
|
2012-04-19 14:35:52 +08:00
|
|
|
m_emitter->initWithTotalParticles(1000);
|
|
|
|
//m_emitter->autorelease();
|
|
|
|
|
|
|
|
m_background->addChild(m_emitter, 10);
|
|
|
|
////m_emitter->release();
|
|
|
|
|
|
|
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
|
|
|
|
// duration
|
|
|
|
m_emitter->setDuration(-1);
|
|
|
|
|
|
|
|
// gravity
|
2012-10-23 17:48:50 +08:00
|
|
|
m_emitter->setGravity(ccp(0,0));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// angle
|
|
|
|
m_emitter->setAngle(0);
|
|
|
|
m_emitter->setAngleVar(360);
|
|
|
|
|
|
|
|
// radial
|
|
|
|
m_emitter->setRadialAccel(70);
|
|
|
|
m_emitter->setRadialAccelVar(10);
|
|
|
|
|
|
|
|
// tagential
|
|
|
|
m_emitter->setTangentialAccel(80);
|
|
|
|
m_emitter->setTangentialAccelVar(0);
|
|
|
|
|
|
|
|
// speed of particles
|
|
|
|
m_emitter->setSpeed(50);
|
|
|
|
m_emitter->setSpeedVar(10);
|
|
|
|
|
|
|
|
// emitter position
|
2012-10-23 17:48:50 +08:00
|
|
|
m_emitter->setPosition( ccp( s.width/2, s.height/2) );
|
2012-04-19 14:35:52 +08:00
|
|
|
m_emitter->setPosVar(CCPointZero);
|
|
|
|
|
|
|
|
// life of particles
|
|
|
|
m_emitter->setLife(2.0f);
|
|
|
|
m_emitter->setLifeVar(0.3f);
|
|
|
|
|
|
|
|
// emits per frame
|
|
|
|
m_emitter->setEmissionRate(m_emitter->getTotalParticles()/m_emitter->getLife());
|
|
|
|
|
|
|
|
// color of particles
|
|
|
|
ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f};
|
|
|
|
m_emitter->setStartColor(startColor);
|
|
|
|
|
|
|
|
ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f};
|
|
|
|
m_emitter->setStartColorVar(startColorVar);
|
|
|
|
|
|
|
|
ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f};
|
|
|
|
m_emitter->setEndColor(endColor);
|
|
|
|
|
|
|
|
ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f};
|
|
|
|
m_emitter->setEndColorVar(endColorVar);
|
|
|
|
|
|
|
|
// size, in pixels
|
|
|
|
m_emitter->setStartSize(1.0f);
|
|
|
|
m_emitter->setStartSizeVar(1.0f);
|
|
|
|
m_emitter->setEndSize(32.0f);
|
|
|
|
m_emitter->setEndSizeVar(8.0f);
|
|
|
|
|
|
|
|
// texture
|
|
|
|
m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) );
|
|
|
|
|
|
|
|
// additive
|
2012-06-15 15:10:40 +08:00
|
|
|
m_emitter->setBlendAdditive(false);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
std::string DemoModernArt::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Varying size";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoRing
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoRing::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
m_emitter = CCParticleFlower::create();
|
2010-09-13 18:07:12 +08:00
|
|
|
m_emitter->retain();
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_background->addChild(m_emitter, 10);
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_stars1) );
|
|
|
|
m_emitter->setLifeVar(0);
|
|
|
|
m_emitter->setLife(10);
|
|
|
|
m_emitter->setSpeed(100);
|
|
|
|
m_emitter->setSpeedVar(0);
|
|
|
|
m_emitter->setEmissionRate(10000);
|
|
|
|
|
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
std::string DemoRing::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Ring Demo";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ParallaxParticle
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ParallaxParticle::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
|
|
|
|
|
|
|
m_background->getParent()->removeChild(m_background, true);
|
2012-04-04 21:58:04 +08:00
|
|
|
m_background = NULL;
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCParallaxNode* p = CCParallaxNode::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(p, 5);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCSprite *p1 = CCSprite::create(s_back3);
|
|
|
|
CCSprite *p2 = CCSprite::create(s_back3);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-10-23 17:48:50 +08:00
|
|
|
p->addChild( p1, 1, ccp(0.5f,1), ccp(0,250) );
|
|
|
|
p->addChild(p2, 2, ccp(1.5f,1), ccp(0,50) );
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
m_emitter = CCParticleFlower::create();
|
2012-04-04 21:58:04 +08:00
|
|
|
m_emitter->retain();
|
|
|
|
m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) );
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
p1->addChild(m_emitter, 10);
|
2012-10-23 17:48:50 +08:00
|
|
|
m_emitter->setPosition( ccp(250,200) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCParticleSun* par = CCParticleSun::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
p2->addChild(par, 10);
|
2012-04-04 21:58:04 +08:00
|
|
|
par->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-10-23 17:48:50 +08:00
|
|
|
CCActionInterval* move = CCMoveBy::create(4, ccp(300,0));
|
2012-04-19 14:35:52 +08:00
|
|
|
CCActionInterval* move_back = move->reverse();
|
2012-12-10 14:12:56 +08:00
|
|
|
CCSequence* seq = CCSequence::create( move, move_back, NULL);
|
|
|
|
p->runAction(CCRepeatForever::create(seq));
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-09-25 11:54:33 +08:00
|
|
|
std::string ParallaxParticle::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Parallax + Particles";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-09-25 11:54:33 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// RadiusMode1
|
|
|
|
//
|
2012-04-04 21:58:04 +08:00
|
|
|
//------------------------------------------------------------------
|
2010-09-25 11:54:33 +08:00
|
|
|
void RadiusMode1::onEnter()
|
|
|
|
{
|
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-07 08:12:28 +08:00
|
|
|
m_color->setColor(ccBLACK);
|
2012-04-04 21:58:04 +08:00
|
|
|
removeChild(m_background, true);
|
|
|
|
m_background = NULL;
|
|
|
|
|
|
|
|
m_emitter = new CCParticleSystemQuad();
|
|
|
|
m_emitter->initWithTotalParticles(200);
|
|
|
|
addChild(m_emitter, 10);
|
|
|
|
m_emitter->setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/stars-grayscale.png"));
|
|
|
|
|
|
|
|
// duration
|
|
|
|
m_emitter->setDuration(kCCParticleDurationInfinity);
|
|
|
|
|
|
|
|
// radius mode
|
|
|
|
m_emitter->setEmitterMode(kCCParticleModeRadius);
|
|
|
|
|
|
|
|
// radius mode: start and end radius in pixels
|
|
|
|
m_emitter->setStartRadius(0);
|
|
|
|
m_emitter->setStartRadiusVar(0);
|
|
|
|
m_emitter->setEndRadius(160);
|
|
|
|
m_emitter->setEndRadiusVar(0);
|
|
|
|
|
|
|
|
// radius mode: degrees per second
|
|
|
|
m_emitter->setRotatePerSecond(180);
|
|
|
|
m_emitter->setRotatePerSecondVar(0);
|
|
|
|
|
|
|
|
|
|
|
|
// angle
|
|
|
|
m_emitter->setAngle(90);
|
|
|
|
m_emitter->setAngleVar(0);
|
|
|
|
|
|
|
|
// emitter position
|
|
|
|
CCSize size = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
m_emitter->setPosition(ccp(size.width/2, size.height/2));
|
|
|
|
m_emitter->setPosVar(CCPointZero);
|
|
|
|
|
|
|
|
// life of particles
|
|
|
|
m_emitter->setLife(5);
|
|
|
|
m_emitter->setLifeVar(0);
|
|
|
|
|
|
|
|
// spin of particles
|
|
|
|
m_emitter->setStartSpin(0);
|
|
|
|
m_emitter->setStartSpinVar(0);
|
|
|
|
m_emitter->setEndSpin(0);
|
|
|
|
m_emitter->setEndSpinVar(0);
|
|
|
|
|
|
|
|
// color of particles
|
|
|
|
ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f};
|
|
|
|
m_emitter->setStartColor(startColor);
|
|
|
|
|
|
|
|
ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f};
|
|
|
|
m_emitter->setStartColorVar(startColorVar);
|
|
|
|
|
|
|
|
ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f};
|
|
|
|
m_emitter->setEndColor(endColor);
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f};
|
2012-04-04 21:58:04 +08:00
|
|
|
m_emitter->setEndColorVar(endColorVar);
|
|
|
|
|
|
|
|
// size, in pixels
|
|
|
|
m_emitter->setStartSize(32);
|
|
|
|
m_emitter->setStartSizeVar(0);
|
|
|
|
m_emitter->setEndSize(kCCParticleStartSizeEqualToEndSize);
|
|
|
|
|
|
|
|
// emits per second
|
|
|
|
m_emitter->setEmissionRate(m_emitter->getTotalParticles() / m_emitter->getLife());
|
|
|
|
|
2010-09-25 11:54:33 +08:00
|
|
|
// additive
|
2012-06-15 15:10:40 +08:00
|
|
|
m_emitter->setBlendAdditive(false);
|
2010-09-25 11:54:33 +08:00
|
|
|
}
|
|
|
|
|
2012-04-04 21:58:04 +08:00
|
|
|
std::string RadiusMode1::title()
|
|
|
|
{
|
|
|
|
return "Radius Mode: Spiral";
|
|
|
|
}
|
|
|
|
|
2010-09-25 11:54:33 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// RadiusMode2
|
|
|
|
//
|
2012-04-04 21:58:04 +08:00
|
|
|
//------------------------------------------------------------------
|
2010-09-25 11:54:33 +08:00
|
|
|
void RadiusMode2::onEnter()
|
|
|
|
{
|
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-07 08:12:28 +08:00
|
|
|
m_color->setColor(ccBLACK);
|
2012-04-04 21:58:04 +08:00
|
|
|
removeChild(m_background, true);
|
|
|
|
m_background = NULL;
|
|
|
|
|
|
|
|
m_emitter = new CCParticleSystemQuad();
|
|
|
|
m_emitter->initWithTotalParticles(200);
|
|
|
|
addChild(m_emitter, 10);
|
|
|
|
m_emitter->setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/stars-grayscale.png"));
|
|
|
|
|
|
|
|
// duration
|
|
|
|
m_emitter->setDuration(kCCParticleDurationInfinity);
|
|
|
|
|
|
|
|
// radius mode
|
|
|
|
m_emitter->setEmitterMode(kCCParticleModeRadius);
|
|
|
|
|
|
|
|
// radius mode: start and end radius in pixels
|
|
|
|
m_emitter->setStartRadius(100);
|
|
|
|
m_emitter->setStartRadiusVar(0);
|
|
|
|
m_emitter->setEndRadius(kCCParticleStartRadiusEqualToEndRadius);
|
|
|
|
m_emitter->setEndRadiusVar(0);
|
|
|
|
|
|
|
|
// radius mode: degrees per second
|
|
|
|
m_emitter->setRotatePerSecond(45);
|
|
|
|
m_emitter->setRotatePerSecondVar(0);
|
|
|
|
|
|
|
|
|
|
|
|
// angle
|
|
|
|
m_emitter->setAngle(90);
|
|
|
|
m_emitter->setAngleVar(0);
|
|
|
|
|
|
|
|
// emitter position
|
|
|
|
CCSize size = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
m_emitter->setPosition(ccp(size.width/2, size.height/2));
|
|
|
|
m_emitter->setPosVar(CCPointZero);
|
|
|
|
|
|
|
|
// life of particles
|
|
|
|
m_emitter->setLife(4);
|
|
|
|
m_emitter->setLifeVar(0);
|
|
|
|
|
|
|
|
// spin of particles
|
|
|
|
m_emitter->setStartSpin(0);
|
|
|
|
m_emitter->setStartSpinVar(0);
|
|
|
|
m_emitter->setEndSpin(0);
|
|
|
|
m_emitter->setEndSpinVar(0);
|
|
|
|
|
|
|
|
// color of particles
|
|
|
|
ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f};
|
|
|
|
m_emitter->setStartColor(startColor);
|
|
|
|
|
|
|
|
ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f};
|
|
|
|
m_emitter->setStartColorVar(startColorVar);
|
|
|
|
|
|
|
|
ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f};
|
|
|
|
m_emitter->setEndColor(endColor);
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f};
|
2012-04-04 21:58:04 +08:00
|
|
|
m_emitter->setEndColorVar(endColorVar);
|
|
|
|
|
|
|
|
// size, in pixels
|
|
|
|
m_emitter->setStartSize(32);
|
|
|
|
m_emitter->setStartSizeVar(0);
|
|
|
|
m_emitter->setEndSize(kCCParticleStartSizeEqualToEndSize);
|
|
|
|
|
|
|
|
// emits per second
|
|
|
|
m_emitter->setEmissionRate(m_emitter->getTotalParticles() / m_emitter->getLife());
|
|
|
|
|
2010-09-25 11:54:33 +08:00
|
|
|
// additive
|
2012-06-15 15:10:40 +08:00
|
|
|
m_emitter->setBlendAdditive(false);
|
2010-09-25 11:54:33 +08:00
|
|
|
}
|
|
|
|
|
2012-04-04 21:58:04 +08:00
|
|
|
std::string RadiusMode2::title()
|
|
|
|
{
|
|
|
|
return "Radius Mode: Semi Circle";
|
|
|
|
}
|
|
|
|
|
2010-09-25 11:54:33 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Issue704
|
|
|
|
//
|
2012-04-04 21:58:04 +08:00
|
|
|
//------------------------------------------------------------------
|
2010-09-25 11:54:33 +08:00
|
|
|
void Issue704::onEnter()
|
|
|
|
{
|
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-07 08:12:28 +08:00
|
|
|
m_color->setColor(ccBLACK);
|
2012-04-04 21:58:04 +08:00
|
|
|
removeChild(m_background, true);
|
|
|
|
m_background = NULL;
|
|
|
|
|
|
|
|
m_emitter = new CCParticleSystemQuad();
|
|
|
|
m_emitter->initWithTotalParticles(100);
|
|
|
|
addChild(m_emitter, 10);
|
|
|
|
m_emitter->setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/fire.png"));
|
|
|
|
|
|
|
|
// duration
|
|
|
|
m_emitter->setDuration(kCCParticleDurationInfinity);
|
|
|
|
|
|
|
|
// radius mode
|
|
|
|
m_emitter->setEmitterMode(kCCParticleModeRadius);
|
|
|
|
|
|
|
|
// radius mode: start and end radius in pixels
|
|
|
|
m_emitter->setStartRadius(50);
|
|
|
|
m_emitter->setStartRadiusVar(0);
|
|
|
|
m_emitter->setEndRadius(kCCParticleStartRadiusEqualToEndRadius);
|
|
|
|
m_emitter->setEndRadiusVar(0);
|
|
|
|
|
|
|
|
// radius mode: degrees per second
|
|
|
|
m_emitter->setRotatePerSecond(0);
|
|
|
|
m_emitter->setRotatePerSecondVar(0);
|
|
|
|
|
|
|
|
|
|
|
|
// angle
|
|
|
|
m_emitter->setAngle(90);
|
|
|
|
m_emitter->setAngleVar(0);
|
|
|
|
|
|
|
|
// emitter position
|
|
|
|
CCSize size = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
m_emitter->setPosition(ccp(size.width/2, size.height/2));
|
|
|
|
m_emitter->setPosVar(CCPointZero);
|
|
|
|
|
|
|
|
// life of particles
|
|
|
|
m_emitter->setLife(5);
|
|
|
|
m_emitter->setLifeVar(0);
|
|
|
|
|
|
|
|
// spin of particles
|
|
|
|
m_emitter->setStartSpin(0);
|
|
|
|
m_emitter->setStartSpinVar(0);
|
|
|
|
m_emitter->setEndSpin(0);
|
|
|
|
m_emitter->setEndSpinVar(0);
|
|
|
|
|
|
|
|
// color of particles
|
|
|
|
ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f};
|
|
|
|
m_emitter->setStartColor(startColor);
|
|
|
|
|
|
|
|
ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f};
|
|
|
|
m_emitter->setStartColorVar(startColorVar);
|
|
|
|
|
|
|
|
ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f};
|
|
|
|
m_emitter->setEndColor(endColor);
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f};
|
2012-04-04 21:58:04 +08:00
|
|
|
m_emitter->setEndColorVar(endColorVar);
|
|
|
|
|
|
|
|
// size, in pixels
|
|
|
|
m_emitter->setStartSize(16);
|
|
|
|
m_emitter->setStartSizeVar(0);
|
|
|
|
m_emitter->setEndSize(kCCParticleStartSizeEqualToEndSize);
|
|
|
|
|
|
|
|
// emits per second
|
|
|
|
m_emitter->setEmissionRate(m_emitter->getTotalParticles() / m_emitter->getLife());
|
|
|
|
|
2010-09-25 11:54:33 +08:00
|
|
|
// additive
|
2012-06-15 15:10:40 +08:00
|
|
|
m_emitter->setBlendAdditive(false);
|
2010-09-25 11:54:33 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCRotateBy* rot = CCRotateBy::create(16, 360);
|
|
|
|
m_emitter->runAction(CCRepeatForever::create(rot));
|
2010-09-25 11:54:33 +08:00
|
|
|
}
|
|
|
|
|
2012-04-04 21:58:04 +08:00
|
|
|
std::string Issue704::title()
|
|
|
|
{
|
|
|
|
return "Issue 704. Free + Rot";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Issue704::subtitle()
|
|
|
|
{
|
|
|
|
return "Emitted particles should not rotate";
|
|
|
|
}
|
|
|
|
|
2010-09-25 11:54:33 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Issue870
|
|
|
|
//
|
2012-04-04 21:58:04 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
void Issue870::onEnter()
|
|
|
|
{
|
|
|
|
ParticleDemo::onEnter();
|
|
|
|
|
2013-06-07 08:12:28 +08:00
|
|
|
m_color->setColor(ccBLACK);
|
2012-04-04 21:58:04 +08:00
|
|
|
removeChild(m_background, true);
|
|
|
|
m_background = NULL;
|
|
|
|
|
|
|
|
CCParticleSystemQuad *system = new CCParticleSystemQuad();
|
2012-05-25 16:52:47 +08:00
|
|
|
system->initWithFile("Particles/SpinningPeas.plist");
|
2012-04-04 21:58:04 +08:00
|
|
|
system->setTextureWithRect(CCTextureCache::sharedTextureCache()->addImage("Images/particles.png"), CCRectMake(0,0,32,32));
|
|
|
|
addChild(system, 10);
|
|
|
|
m_emitter = system;
|
|
|
|
|
|
|
|
m_nIndex = 0;
|
|
|
|
schedule(schedule_selector(Issue870::updateQuads), 2.0f);
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void Issue870::updateQuads(float dt)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
|
|
|
m_nIndex = (m_nIndex + 1) % 4;
|
|
|
|
CCRect rect = CCRectMake(m_nIndex * 32, 0, 32, 32);
|
|
|
|
CCParticleSystemQuad* system = (CCParticleSystemQuad*)m_emitter;
|
|
|
|
system->setTextureWithRect(m_emitter->getTexture(), rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Issue870::title()
|
|
|
|
{
|
|
|
|
return "Issue 870. SubRect";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Issue870::subtitle()
|
|
|
|
{
|
|
|
|
return "Every 2 seconds the particle should change";
|
|
|
|
}
|
|
|
|
|
2010-09-25 11:54:33 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoParticleFromFile
|
|
|
|
//
|
2012-04-04 21:58:04 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoParticleFromFile::onEnter()
|
|
|
|
{
|
|
|
|
ParticleDemo::onEnter();
|
|
|
|
|
2013-06-07 08:12:28 +08:00
|
|
|
m_color->setColor(ccBLACK);
|
2012-04-19 14:35:52 +08:00
|
|
|
removeChild(m_background, true);
|
|
|
|
m_background = NULL;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
m_emitter = new CCParticleSystemQuad();
|
2012-05-25 16:52:47 +08:00
|
|
|
std::string filename = "Particles/" + m_title + ".plist";
|
2012-04-04 21:58:04 +08:00
|
|
|
m_emitter->initWithFile(filename.c_str());
|
|
|
|
addChild(m_emitter, 10);
|
|
|
|
|
|
|
|
setEmitterPosition();
|
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ParticleDemo
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
enum
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
IDC_NEXT = 100,
|
|
|
|
IDC_BACK,
|
|
|
|
IDC_RESTART,
|
|
|
|
IDC_TOGGLE
|
2010-08-23 16:38:10 +08:00
|
|
|
};
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
static int sceneIdx = -1;
|
|
|
|
|
2013-01-22 01:35:59 +08:00
|
|
|
#define MAX_LAYER 44
|
2010-08-23 16:38:10 +08:00
|
|
|
|
|
|
|
CCLayer* createParticleLayer(int nIndex)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
switch(nIndex)
|
|
|
|
{
|
|
|
|
case 0: return new ParticleReorder();
|
|
|
|
case 1: return new ParticleBatchHybrid();
|
|
|
|
case 2: return new ParticleBatchMultipleEmitters();
|
|
|
|
case 3: return new DemoFlower();
|
|
|
|
case 4: return new DemoGalaxy();
|
|
|
|
case 5: return new DemoFirework();
|
|
|
|
case 6: return new DemoSpiral();
|
|
|
|
case 7: return new DemoSun();
|
|
|
|
case 8: return new DemoMeteor();
|
|
|
|
case 9: return new DemoFire();
|
|
|
|
case 10: return new DemoSmoke();
|
|
|
|
case 11: return new DemoExplosion();
|
|
|
|
case 12: return new DemoSnow();
|
|
|
|
case 13: return new DemoRain();
|
|
|
|
case 14: return new DemoBigFlower();
|
|
|
|
case 15: return new DemoRotFlower();
|
|
|
|
case 16: return new DemoModernArt();
|
|
|
|
case 17: return new DemoRing();
|
|
|
|
case 18: return new ParallaxParticle();
|
2012-04-04 21:58:04 +08:00
|
|
|
case 19: return new DemoParticleFromFile("BoilingFoam");
|
|
|
|
case 20: return new DemoParticleFromFile("BurstPipe");
|
|
|
|
case 21: return new DemoParticleFromFile("Comet");
|
|
|
|
case 22: return new DemoParticleFromFile("debian");
|
|
|
|
case 23: return new DemoParticleFromFile("ExplodingRing");
|
|
|
|
case 24: return new DemoParticleFromFile("LavaFlow");
|
|
|
|
case 25: return new DemoParticleFromFile("SpinningPeas");
|
|
|
|
case 26: return new DemoParticleFromFile("SpookyPeas");
|
2012-03-22 18:29:07 +08:00
|
|
|
case 27: return new DemoParticleFromFile("Upsidedown");
|
2012-04-04 21:58:04 +08:00
|
|
|
case 28: return new DemoParticleFromFile("Flower");
|
|
|
|
case 29: return new DemoParticleFromFile("Spiral");
|
2012-03-22 18:29:07 +08:00
|
|
|
case 30: return new DemoParticleFromFile("Galaxy");
|
2012-04-19 14:35:52 +08:00
|
|
|
case 31: return new DemoParticleFromFile("Phoenix");
|
2013-01-22 01:35:59 +08:00
|
|
|
case 32: return new DemoParticleFromFile("lines");
|
|
|
|
case 33: return new RadiusMode1();
|
|
|
|
case 34: return new RadiusMode2();
|
|
|
|
case 35: return new Issue704();
|
|
|
|
case 36: return new Issue870();
|
|
|
|
case 37: return new Issue1201();
|
2012-04-19 14:35:52 +08:00
|
|
|
// v1.1 tests
|
2013-01-22 01:35:59 +08:00
|
|
|
case 38: return new MultipleParticleSystems();
|
|
|
|
case 39: return new MultipleParticleSystemsBatched();
|
|
|
|
case 40: return new AddAndDeleteParticleSystems();
|
|
|
|
case 41: return new ReorderParticleSystems();
|
|
|
|
case 42: return new PremultipliedAlphaTest();
|
|
|
|
case 43: return new PremultipliedAlphaTest2();
|
2012-04-19 14:35:52 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return NULL;
|
2010-08-23 16:38:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CCLayer* nextParticleAction()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
sceneIdx++;
|
|
|
|
sceneIdx = sceneIdx % MAX_LAYER;
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCLayer* pLayer = createParticleLayer(sceneIdx);
|
|
|
|
pLayer->autorelease();
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return pLayer;
|
2010-08-23 16:38:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCLayer* backParticleAction()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
sceneIdx--;
|
|
|
|
int total = MAX_LAYER;
|
|
|
|
if( sceneIdx < 0 )
|
|
|
|
sceneIdx += total;
|
|
|
|
|
|
|
|
CCLayer* pLayer = createParticleLayer(sceneIdx);
|
|
|
|
pLayer->autorelease();
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return pLayer;
|
2010-08-23 16:38:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCLayer* restartParticleAction()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCLayer* pLayer = createParticleLayer(sceneIdx);
|
|
|
|
pLayer->autorelease();
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return pLayer;
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:02:18 +08:00
|
|
|
ParticleDemo::~ParticleDemo(void)
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE(m_emitter);
|
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-24 15:02:18 +08:00
|
|
|
void ParticleDemo::onEnter(void)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2013-06-07 08:12:28 +08:00
|
|
|
BaseTest::onEnter();
|
|
|
|
|
|
|
|
m_color = CCLayerColor::create( ccc4(127,127,127,255) );
|
|
|
|
this->addChild(m_color);
|
2012-04-24 15:02:18 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_emitter = NULL;
|
2012-04-24 15:02:18 +08:00
|
|
|
|
2012-06-15 15:10:40 +08:00
|
|
|
setTouchEnabled( true );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
2012-04-24 15:02:18 +08:00
|
|
|
|
2013-06-14 11:36:43 +08:00
|
|
|
CCMenuItemToggle* item4 = CCMenuItemToggle::createWithCallback( CC_CALLBACK_1(ParticleDemo::toggleCallback, this),
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemFont::create( "Free Movement" ),
|
|
|
|
CCMenuItemFont::create( "Relative Movement" ),
|
|
|
|
CCMenuItemFont::create( "Grouped Movement" ),
|
2012-04-24 15:02:18 +08:00
|
|
|
NULL );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-07 08:12:28 +08:00
|
|
|
CCMenu *menu = CCMenu::create(item4, NULL);
|
2012-04-24 15:02:18 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
menu->setPosition( CCPointZero );
|
2012-10-23 17:48:50 +08:00
|
|
|
item4->setPosition( ccp( VisibleRect::left().x, VisibleRect::bottom().y+ 100) );
|
2012-06-12 15:40:31 +08:00
|
|
|
item4->setAnchorPoint( ccp(0,0) );
|
2012-04-24 15:02:18 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild( menu, 100 );
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCLabelAtlas* labelAtlas = CCLabelAtlas::create("0000", "fps_images.png", 12, 32, '.');
|
2012-04-04 21:58:04 +08:00
|
|
|
addChild(labelAtlas, 100, kTagParticleCount);
|
2012-06-12 15:40:31 +08:00
|
|
|
labelAtlas->setPosition(ccp(s.width-66,50));
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// moving background
|
2012-06-14 15:13:16 +08:00
|
|
|
m_background = CCSprite::create(s_back3);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(m_background, 5);
|
2012-06-12 15:40:31 +08:00
|
|
|
m_background->setPosition( ccp(s.width/2, s.height-180) );
|
2012-04-24 15:02:18 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCActionInterval* move = CCMoveBy::create(4, ccp(300,0) );
|
2012-04-19 14:35:52 +08:00
|
|
|
CCActionInterval* move_back = move->reverse();
|
2012-12-10 14:12:56 +08:00
|
|
|
CCSequence* seq = CCSequence::create( move, move_back, NULL);
|
|
|
|
m_background->runAction( CCRepeatForever::create(seq) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
scheduleUpdate();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string ParticleDemo::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "No title";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:02:18 +08:00
|
|
|
std::string ParticleDemo::subtitle()
|
|
|
|
{
|
|
|
|
return "No titile";
|
|
|
|
}
|
|
|
|
|
2012-11-20 17:39:11 +08:00
|
|
|
void ParticleDemo::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2012-11-20 17:39:11 +08:00
|
|
|
ccTouchesEnded(pTouches, pEvent);
|
2010-08-23 16:38:10 +08:00
|
|
|
}
|
|
|
|
|
2012-11-20 17:39:11 +08:00
|
|
|
void ParticleDemo::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2012-11-20 17:39:11 +08:00
|
|
|
return ccTouchesEnded(pTouches, pEvent);
|
2010-08-23 16:38:10 +08:00
|
|
|
}
|
|
|
|
|
2012-11-20 17:39:11 +08:00
|
|
|
void ParticleDemo::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent)
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2012-11-20 17:39:11 +08:00
|
|
|
CCTouch *touch = (CCTouch*)pTouches->anyObject();
|
|
|
|
|
2012-07-31 17:41:53 +08:00
|
|
|
CCPoint location = touch->getLocation();
|
2010-09-25 11:54:33 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCPoint pos = CCPointZero;
|
2010-09-25 11:54:33 +08:00
|
|
|
if (m_background)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
pos = m_background->convertToWorldSpace(CCPointZero);
|
2010-09-25 11:54:33 +08:00
|
|
|
}
|
2012-03-22 18:29:07 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if (m_emitter != NULL)
|
|
|
|
{
|
2012-07-31 17:41:53 +08:00
|
|
|
m_emitter->setPosition( ccpSub(location, pos) );
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2010-08-23 16:38:10 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void ParticleDemo::update(float dt)
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2010-08-25 13:45:28 +08:00
|
|
|
if (m_emitter)
|
|
|
|
{
|
2012-04-04 21:58:04 +08:00
|
|
|
CCLabelAtlas* atlas = (CCLabelAtlas*)getChildByTag(kTagParticleCount);
|
|
|
|
char str[5] = {0};
|
|
|
|
sprintf(str, "%04d", m_emitter->getParticleCount());
|
|
|
|
atlas->setString(str);
|
|
|
|
}
|
2010-08-23 16:38:10 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void ParticleDemo::toggleCallback(CCObject* pSender)
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
if (m_emitter != NULL)
|
|
|
|
{
|
|
|
|
if( m_emitter->getPositionType() == kCCPositionTypeGrouped )
|
|
|
|
m_emitter->setPositionType( kCCPositionTypeFree );
|
|
|
|
else if (m_emitter->getPositionType() == kCCPositionTypeFree)
|
|
|
|
m_emitter->setPositionType(kCCPositionTypeRelative);
|
|
|
|
else if (m_emitter->getPositionType() == kCCPositionTypeRelative)
|
|
|
|
m_emitter->setPositionType( kCCPositionTypeGrouped );
|
|
|
|
}
|
2010-08-23 16:38:10 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void ParticleDemo::restartCallback(CCObject* pSender)
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
if (m_emitter != NULL)
|
|
|
|
{
|
|
|
|
m_emitter->resetSystem();
|
|
|
|
}
|
2010-08-23 16:38:10 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void ParticleDemo::nextCallback(CCObject* pSender)
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCScene* s = new ParticleTestScene();
|
|
|
|
s->addChild( nextParticleAction() );
|
|
|
|
CCDirector::sharedDirector()->replaceScene(s);
|
2010-09-16 16:32:14 +08:00
|
|
|
s->release();
|
2010-08-23 16:38:10 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void ParticleDemo::backCallback(CCObject* pSender)
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCScene* s = new ParticleTestScene();
|
|
|
|
s->addChild( backParticleAction() );
|
|
|
|
CCDirector::sharedDirector()->replaceScene(s);
|
2010-09-16 16:32:14 +08:00
|
|
|
s->release();
|
2010-08-23 16:38:10 +08:00
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
void ParticleDemo::setEmitterPosition()
|
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
if (m_emitter != NULL)
|
|
|
|
{
|
2012-10-23 17:48:50 +08:00
|
|
|
m_emitter->setPosition( ccp(s.width / 2, s.height / 2) );
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ParticleBatchHybrid
|
|
|
|
|
|
|
|
void ParticleBatchHybrid::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-07 08:12:28 +08:00
|
|
|
m_color->setColor(ccBLACK);
|
2012-04-19 14:35:52 +08:00
|
|
|
removeChild(m_background, true);
|
|
|
|
m_background = NULL;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
m_emitter = CCParticleSystemQuad::create("Particles/LavaFlow.plist");
|
2012-04-19 14:35:52 +08:00
|
|
|
m_emitter->retain();
|
2012-07-23 22:49:11 +08:00
|
|
|
CCParticleBatchNode *batch = CCParticleBatchNode::createWithTexture(m_emitter->getTexture());
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
batch->addChild(m_emitter);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(batch, 10);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
schedule(schedule_selector(ParticleBatchHybrid::switchRender), 2.0f);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCNode *node = CCNode::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(node);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_pParent1 = batch;
|
|
|
|
m_pParent2 = node;
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void ParticleBatchHybrid::switchRender(float dt)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
bool usingBatch = ( m_emitter->getBatchNode() != NULL );
|
|
|
|
m_emitter->removeFromParentAndCleanup(false);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCNode *newParent = (usingBatch ? m_pParent2 : m_pParent1 );
|
|
|
|
newParent->addChild(m_emitter);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
CCLog("Particle: Using new parent: %s", usingBatch ? "CCNode" : "CCParticleBatchNode");
|
|
|
|
}
|
|
|
|
|
2012-03-22 18:29:07 +08:00
|
|
|
std::string ParticleBatchHybrid::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Paticle Batch";
|
2012-03-22 18:29:07 +08:00
|
|
|
}
|
2010-08-26 09:55:54 +08:00
|
|
|
|
2012-04-04 21:58:04 +08:00
|
|
|
std::string ParticleBatchHybrid::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Hybrid: batched and non batched every 2 seconds";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ParticleBatchMultipleEmitters
|
|
|
|
|
|
|
|
void ParticleBatchMultipleEmitters::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-07 08:12:28 +08:00
|
|
|
m_color->setColor(ccBLACK);
|
2012-04-19 14:35:52 +08:00
|
|
|
removeChild(m_background, true);
|
|
|
|
m_background = NULL;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCParticleSystemQuad *emitter1 = CCParticleSystemQuad::create("Particles/LavaFlow.plist");
|
2012-04-19 14:35:52 +08:00
|
|
|
emitter1->setStartColor(ccc4f(1,0,0,1));
|
2012-06-14 15:13:16 +08:00
|
|
|
CCParticleSystemQuad *emitter2 = CCParticleSystemQuad::create("Particles/LavaFlow.plist");
|
2012-04-19 14:35:52 +08:00
|
|
|
emitter2->setStartColor(ccc4f(0,1,0,1));
|
2012-06-14 15:13:16 +08:00
|
|
|
CCParticleSystemQuad *emitter3 = CCParticleSystemQuad::create("Particles/LavaFlow.plist");
|
2012-04-19 14:35:52 +08:00
|
|
|
emitter3->setStartColor(ccc4f(0,0,1,1));
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
emitter1->setPosition(ccp( s.width/1.25f, s.height/1.25f));
|
|
|
|
emitter2->setPosition(ccp( s.width/2, s.height/2));
|
|
|
|
emitter3->setPosition(ccp( s.width/4, s.height/4));
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-07-23 22:49:11 +08:00
|
|
|
CCParticleBatchNode *batch = CCParticleBatchNode::createWithTexture(emitter1->getTexture());
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
batch->addChild(emitter1, 0);
|
|
|
|
batch->addChild(emitter2, 0);
|
|
|
|
batch->addChild(emitter3, 0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(batch, 10);
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2012-03-22 18:29:07 +08:00
|
|
|
std::string ParticleBatchMultipleEmitters::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Paticle Batch";
|
2012-03-22 18:29:07 +08:00
|
|
|
}
|
|
|
|
|
2012-04-04 21:58:04 +08:00
|
|
|
std::string ParticleBatchMultipleEmitters::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Multiple emitters. One Batch";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ParticleReorder
|
|
|
|
|
|
|
|
void ParticleReorder::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_nOrder = 0;
|
2013-06-07 08:12:28 +08:00
|
|
|
m_color->setColor(ccBLACK);
|
2012-04-19 14:35:52 +08:00
|
|
|
removeChild(m_background, true);
|
|
|
|
m_background = NULL;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCParticleSystem* ignore = CCParticleSystemQuad::create("Particles/SmallSun.plist");
|
|
|
|
CCNode *parent1 = CCNode::create();
|
2012-07-23 22:49:11 +08:00
|
|
|
CCNode *parent2 = CCParticleBatchNode::createWithTexture(ignore->getTexture());
|
2012-04-04 21:58:04 +08:00
|
|
|
ignore->unscheduleUpdate();
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
for( unsigned int i=0; i<2;i++)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCNode *parent = ( i==0 ? parent1 : parent2 );
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCParticleSystemQuad *emitter1 = CCParticleSystemQuad::create("Particles/SmallSun.plist");
|
2012-04-19 14:35:52 +08:00
|
|
|
emitter1->setStartColor(ccc4f(1,0,0,1));
|
2012-06-15 15:10:40 +08:00
|
|
|
emitter1->setBlendAdditive(false);
|
2012-06-14 15:13:16 +08:00
|
|
|
CCParticleSystemQuad *emitter2 = CCParticleSystemQuad::create("Particles/SmallSun.plist");
|
2012-04-19 14:35:52 +08:00
|
|
|
emitter2->setStartColor(ccc4f(0,1,0,1));
|
2012-06-15 15:10:40 +08:00
|
|
|
emitter2->setBlendAdditive(false);
|
2012-06-14 15:13:16 +08:00
|
|
|
CCParticleSystemQuad *emitter3 = CCParticleSystemQuad::create("Particles/SmallSun.plist");
|
2012-04-19 14:35:52 +08:00
|
|
|
emitter3->setStartColor(ccc4f(0,0,1,1));
|
2012-06-15 15:10:40 +08:00
|
|
|
emitter3->setBlendAdditive(false);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
int neg = (i==0 ? 1 : -1 );
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
emitter1->setPosition(ccp( s.width/2-30, s.height/2+60*neg));
|
|
|
|
emitter2->setPosition(ccp( s.width/2, s.height/2+60*neg));
|
|
|
|
emitter3->setPosition(ccp( s.width/2+30, s.height/2+60*neg));
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
parent->addChild(emitter1, 0, 1);
|
|
|
|
parent->addChild(emitter2, 0, 2);
|
|
|
|
parent->addChild(emitter3, 0, 3);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(parent, 10, 1000+i);
|
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
schedule(schedule_selector(ParticleReorder::reorderParticles), 1.0f);
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string ParticleReorder::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Reordering particles";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string ParticleReorder::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Reordering particles with and without batches batches";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void ParticleReorder::reorderParticles(float dt)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
for( int i=0; i<2;i++) {
|
|
|
|
CCNode *parent = getChildByTag(1000+i);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCNode *child1 = parent->getChildByTag(1);
|
|
|
|
CCNode *child2 = parent->getChildByTag(2);
|
|
|
|
CCNode *child3 = parent->getChildByTag(3);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if( m_nOrder % 3 == 0 ) {
|
|
|
|
parent->reorderChild(child1, 1);
|
|
|
|
parent->reorderChild(child2, 2);
|
|
|
|
parent->reorderChild(child3, 3);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
} else if (m_nOrder % 3 == 1 ) {
|
|
|
|
parent->reorderChild(child1, 3);
|
|
|
|
parent->reorderChild(child2, 1);
|
|
|
|
parent->reorderChild(child3, 2);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
} else if (m_nOrder % 3 == 2 ) {
|
|
|
|
parent->reorderChild(child1, 2);
|
|
|
|
parent->reorderChild(child2, 3);
|
|
|
|
parent->reorderChild(child3, 1);
|
|
|
|
}
|
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_nOrder++;
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
class RainbowEffect : public CCParticleSystemQuad
|
|
|
|
{
|
|
|
|
public:
|
2012-04-19 14:35:52 +08:00
|
|
|
bool init();
|
|
|
|
virtual bool initWithTotalParticles(unsigned int numberOfParticles);
|
2012-06-08 13:55:28 +08:00
|
|
|
virtual void update(float dt);
|
2012-04-04 21:58:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
bool RainbowEffect::init()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return initWithTotalParticles(150);
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RainbowEffect::initWithTotalParticles(unsigned int numberOfParticles)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
if( CCParticleSystemQuad::initWithTotalParticles(numberOfParticles) )
|
|
|
|
{
|
|
|
|
// additive
|
2012-06-15 15:10:40 +08:00
|
|
|
setBlendAdditive(false);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// duration
|
|
|
|
setDuration(kCCParticleDurationInfinity);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// Gravity Mode
|
|
|
|
setEmitterMode(kCCParticleModeGravity);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// Gravity Mode: gravity
|
|
|
|
setGravity(ccp(0,0));
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// Gravity mode: radial acceleration
|
|
|
|
setRadialAccel(0);
|
|
|
|
setRadialAccelVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// Gravity mode: speed of particles
|
|
|
|
setSpeed(120);
|
|
|
|
setSpeedVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// angle
|
|
|
|
setAngle(180);
|
|
|
|
setAngleVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// emitter position
|
|
|
|
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
setPosition(ccp(winSize.width/2, winSize.height/2));
|
|
|
|
setPosVar(CCPointZero);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// life of particles
|
|
|
|
setLife(0.5f);
|
|
|
|
setLifeVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// size, in pixels
|
|
|
|
setStartSize(25.0f);
|
|
|
|
setStartSizeVar(0);
|
|
|
|
setEndSize(kCCParticleStartSizeEqualToEndSize);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// emits per seconds
|
|
|
|
setEmissionRate(getTotalParticles()/getLife());
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// color of particles
|
|
|
|
setStartColor(ccc4FFromccc4B(ccc4(50, 50, 50, 50)));
|
|
|
|
setEndColor(ccc4FFromccc4B(ccc4(0, 0, 0, 0)));
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_tStartColorVar.r = 0.0f;
|
|
|
|
m_tStartColorVar.g = 0.0f;
|
|
|
|
m_tStartColorVar.b = 0.0f;
|
|
|
|
m_tStartColorVar.a = 0.0f;
|
|
|
|
m_tEndColorVar.r = 0.0f;
|
|
|
|
m_tEndColorVar.g = 0.0f;
|
|
|
|
m_tEndColorVar.b = 0.0f;
|
|
|
|
m_tEndColorVar.a = 0.0f;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/particles.png"));
|
|
|
|
return true;
|
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return false;
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void RainbowEffect::update(float dt)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
m_fEmitCounter = 0;
|
|
|
|
CCParticleSystemQuad::update(dt);
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Issue1201::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-07 08:12:28 +08:00
|
|
|
m_color->setColor(ccBLACK);
|
2012-04-19 14:35:52 +08:00
|
|
|
removeChild(m_background, true);
|
|
|
|
m_background = NULL;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
RainbowEffect *particle = new RainbowEffect();
|
|
|
|
particle->initWithTotalParticles(50);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(particle);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
particle->setPosition(ccp(s.width/2, s.height/2));
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_emitter = particle;
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string Issue1201::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Issue 1201. Unfinished";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string Issue1201::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Unfinished test. Ignore it";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MultipleParticleSystems::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-07 08:12:28 +08:00
|
|
|
m_color->setColor(ccBLACK);
|
2012-04-19 14:35:52 +08:00
|
|
|
removeChild(m_background, true);
|
|
|
|
m_background = NULL;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCTextureCache::sharedTextureCache()->addImage("Images/particles.png");
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
for (int i = 0; i<5; i++) {
|
2012-06-14 15:13:16 +08:00
|
|
|
CCParticleSystemQuad *particleSystem = CCParticleSystemQuad::create("Particles/SpinningPeas.plist");
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setPosition(ccp(i*50 ,i*50));
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setPositionType(kCCPositionTypeGrouped);
|
|
|
|
addChild(particleSystem);
|
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_emitter = NULL;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-22 18:29:07 +08:00
|
|
|
std::string MultipleParticleSystems::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Multiple particle systems";
|
2012-03-22 18:29:07 +08:00
|
|
|
}
|
|
|
|
|
2012-04-04 21:58:04 +08:00
|
|
|
std::string MultipleParticleSystems::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "v1.1 test: FPS should be lower than next test";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void MultipleParticleSystems::update(float dt)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCLabelAtlas *atlas = (CCLabelAtlas*) getChildByTag(kTagParticleCount);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
unsigned int count = 0;
|
|
|
|
|
|
|
|
CCObject* pObj = NULL;
|
2013-02-28 16:40:32 +08:00
|
|
|
CCARRAY_FOREACH(getChildren(), pObj)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
CCParticleSystem* item = dynamic_cast<CCParticleSystem*>(pObj);
|
|
|
|
if (item != NULL)
|
|
|
|
{
|
|
|
|
count += item->getParticleCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
char str[100] = {0};
|
|
|
|
sprintf(str, "%4d", count);
|
|
|
|
atlas->setString(str);
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// MultipleParticleSystemsBatched
|
|
|
|
|
|
|
|
void MultipleParticleSystemsBatched::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-07 08:12:28 +08:00
|
|
|
m_color->setColor(ccBLACK);
|
2012-04-19 14:35:52 +08:00
|
|
|
removeChild(m_background, true);
|
|
|
|
m_background = NULL;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCParticleBatchNode *batchNode = new CCParticleBatchNode();
|
|
|
|
batchNode->initWithTexture(NULL, 3000);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(batchNode, 1, 2);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
for (int i = 0; i<5; i++) {
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCParticleSystemQuad *particleSystem = CCParticleSystemQuad::create("Particles/SpinningPeas.plist");
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setPositionType(kCCPositionTypeGrouped);
|
|
|
|
particleSystem->setPosition(ccp(i*50 ,i*50));
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
batchNode->setTexture(particleSystem->getTexture());
|
|
|
|
batchNode->addChild(particleSystem);
|
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
batchNode->release();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_emitter = NULL;
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void MultipleParticleSystemsBatched::update(float dt)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCLabelAtlas *atlas = (CCLabelAtlas*) getChildByTag(kTagParticleCount);
|
|
|
|
|
|
|
|
unsigned count = 0;
|
|
|
|
|
|
|
|
CCNode* batchNode = getChildByTag(2);
|
|
|
|
CCObject* pObj = NULL;
|
|
|
|
CCARRAY_FOREACH(batchNode->getChildren(), pObj)
|
|
|
|
{
|
|
|
|
CCParticleSystem* item = dynamic_cast<CCParticleSystem*>(pObj);
|
|
|
|
if (item != NULL)
|
|
|
|
{
|
|
|
|
count += item->getParticleCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
char str[50] = {0};
|
|
|
|
sprintf(str, "%4d", count);
|
|
|
|
atlas->setString(str);
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2012-03-22 18:29:07 +08:00
|
|
|
std::string MultipleParticleSystemsBatched::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Multiple particle systems batched";
|
2012-03-22 18:29:07 +08:00
|
|
|
}
|
|
|
|
|
2012-04-04 21:58:04 +08:00
|
|
|
std::string MultipleParticleSystemsBatched::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "v1.1 test: should perform better than previous test";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddAndDeleteParticleSystems
|
|
|
|
|
|
|
|
void AddAndDeleteParticleSystems::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-07 08:12:28 +08:00
|
|
|
m_color->setColor(ccBLACK);
|
2012-04-19 14:35:52 +08:00
|
|
|
removeChild(m_background, true);
|
|
|
|
m_background = NULL;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
//adds the texture inside the plist to the texture cache
|
2012-07-23 22:49:11 +08:00
|
|
|
m_pBatchNode = CCParticleBatchNode::createWithTexture((CCTexture2D*)NULL, 16000);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(m_pBatchNode, 1, 2);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
for (int i = 0; i<6; i++) {
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCParticleSystemQuad *particleSystem = CCParticleSystemQuad::create("Particles/Spiral.plist");
|
2012-04-19 14:35:52 +08:00
|
|
|
m_pBatchNode->setTexture(particleSystem->getTexture());
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setPositionType(kCCPositionTypeGrouped);
|
|
|
|
particleSystem->setTotalParticles(200);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setPosition(ccp(i*15 +100,i*15+100));
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
unsigned int randZ = rand() % 100;
|
|
|
|
m_pBatchNode->addChild(particleSystem, randZ, -1);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
schedule(schedule_selector(AddAndDeleteParticleSystems::removeSystem), 0.5f);
|
|
|
|
m_emitter = NULL;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void AddAndDeleteParticleSystems::removeSystem(float dt)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
int nChildrenCount = m_pBatchNode->getChildren()->count();
|
|
|
|
if (nChildrenCount > 0)
|
|
|
|
{
|
|
|
|
CCLOG("remove random system");
|
|
|
|
unsigned int uRand = rand() % (nChildrenCount - 1);
|
|
|
|
m_pBatchNode->removeChild((CCNode*)m_pBatchNode->getChildren()->objectAtIndex(uRand), true);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCParticleSystemQuad *particleSystem = CCParticleSystemQuad::create("Particles/Spiral.plist");
|
2012-04-19 14:35:52 +08:00
|
|
|
//add new
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setPositionType(kCCPositionTypeGrouped);
|
|
|
|
particleSystem->setTotalParticles(200);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setPosition(ccp(rand() % 300 ,rand() % 400));
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCLOG("add a new system");
|
|
|
|
unsigned int randZ = rand() % 100;
|
|
|
|
m_pBatchNode->addChild(particleSystem, randZ, -1);
|
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void AddAndDeleteParticleSystems::update(float dt)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCLabelAtlas *atlas = (CCLabelAtlas*) getChildByTag(kTagParticleCount);
|
|
|
|
|
|
|
|
unsigned int count = 0;
|
|
|
|
|
|
|
|
CCNode* batchNode = getChildByTag(2);
|
|
|
|
CCObject* pObj = NULL;
|
|
|
|
CCARRAY_FOREACH(batchNode->getChildren(), pObj)
|
|
|
|
{
|
|
|
|
CCParticleSystem* item = dynamic_cast<CCParticleSystem*>(pObj);
|
|
|
|
if (item != NULL)
|
|
|
|
{
|
|
|
|
count += item->getParticleCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
char str[100] = {0};
|
|
|
|
sprintf(str, "%4d", count);
|
|
|
|
atlas->setString(str);
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2012-03-22 18:29:07 +08:00
|
|
|
std::string AddAndDeleteParticleSystems::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Add and remove Particle System";
|
2012-03-22 18:29:07 +08:00
|
|
|
}
|
|
|
|
|
2012-04-04 21:58:04 +08:00
|
|
|
std::string AddAndDeleteParticleSystems::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "v1.1 test: every 2 sec 1 system disappear, 1 appears";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ReorderParticleSystems
|
|
|
|
|
|
|
|
void ReorderParticleSystems::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-07 08:12:28 +08:00
|
|
|
m_color->setColor(ccBLACK);
|
2012-04-19 14:35:52 +08:00
|
|
|
removeChild(m_background ,true);
|
|
|
|
m_background = NULL;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
m_pBatchNode = CCParticleBatchNode::create("Images/stars-grayscale.png" ,3000);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(m_pBatchNode, 1, 2);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
for (int i = 0; i<3; i++) {
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCParticleSystemQuad* particleSystem = new CCParticleSystemQuad();
|
|
|
|
particleSystem->initWithTotalParticles(200);
|
|
|
|
particleSystem->setTexture(m_pBatchNode->getTexture());
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// duration
|
|
|
|
particleSystem->setDuration(kCCParticleDurationInfinity);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// radius mode
|
|
|
|
particleSystem->setEmitterMode(kCCParticleModeRadius);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// radius mode: 100 pixels from center
|
|
|
|
particleSystem->setStartRadius(100);
|
|
|
|
particleSystem->setStartRadiusVar(0);
|
|
|
|
particleSystem->setEndRadius(kCCParticleStartRadiusEqualToEndRadius);
|
|
|
|
particleSystem->setEndRadiusVar(0); // not used when start == end
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// radius mode: degrees per second
|
|
|
|
// 45 * 4 seconds of life = 180 degrees
|
|
|
|
particleSystem->setRotatePerSecond(45);
|
|
|
|
particleSystem->setRotatePerSecondVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// angle
|
|
|
|
particleSystem->setAngle(90);
|
|
|
|
particleSystem->setAngleVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// emitter position
|
|
|
|
particleSystem->setPosVar(CCPointZero);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// life of particles
|
|
|
|
particleSystem->setLife(4);
|
|
|
|
particleSystem->setLifeVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// spin of particles
|
|
|
|
particleSystem->setStartSpin(0);
|
|
|
|
particleSystem->setStartSpinVar(0);
|
|
|
|
particleSystem->setEndSpin(0);
|
|
|
|
particleSystem->setEndSpinVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// color of particles
|
|
|
|
float color[3] = {0,0,0};
|
|
|
|
color[i] = 1;
|
|
|
|
ccColor4F startColor = {color[0], color[1], color[2], 1.0f};
|
|
|
|
particleSystem->setStartColor(startColor);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
ccColor4F startColorVar = {0, 0, 0, 0};
|
|
|
|
particleSystem->setStartColorVar(startColorVar);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
ccColor4F endColor = startColor;
|
|
|
|
particleSystem->setEndColor(endColor);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
ccColor4F endColorVar = startColorVar;
|
|
|
|
particleSystem->setEndColorVar(endColorVar);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// size, in pixels
|
|
|
|
particleSystem->setStartSize(32);
|
|
|
|
particleSystem->setStartSizeVar(0);
|
|
|
|
particleSystem->setEndSize(kCCParticleStartSizeEqualToEndSize);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// emits per second
|
|
|
|
particleSystem->setEmissionRate(particleSystem->getTotalParticles()/particleSystem->getLife());
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// additive
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setPosition(ccp(i*10+120 ,200));
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_pBatchNode->addChild(particleSystem);
|
|
|
|
particleSystem->setPositionType(kCCPositionTypeFree);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->release();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
//[pBNode addChild:particleSystem z:10 tag:0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
schedule(schedule_selector(ReorderParticleSystems::reorderSystem), 2.0f);
|
|
|
|
m_emitter = NULL;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void ReorderParticleSystems::reorderSystem(float time)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCParticleSystem* system = (CCParticleSystem*)m_pBatchNode->getChildren()->objectAtIndex(1);
|
|
|
|
m_pBatchNode->reorderChild(system, system->getZOrder() - 1);
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void ReorderParticleSystems::update(float dt)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCLabelAtlas *atlas = (CCLabelAtlas*) getChildByTag(kTagParticleCount);
|
|
|
|
|
|
|
|
unsigned int count = 0;
|
|
|
|
|
|
|
|
CCNode* batchNode = getChildByTag(2);
|
|
|
|
CCObject* pObj = NULL;
|
|
|
|
CCARRAY_FOREACH(batchNode->getChildren(), pObj)
|
|
|
|
{
|
|
|
|
CCParticleSystem* item = dynamic_cast<CCParticleSystem*>(pObj);
|
|
|
|
if (item != NULL)
|
|
|
|
{
|
|
|
|
count += item->getParticleCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
char str[100] = {0};
|
|
|
|
sprintf(str, "%4d", count);
|
|
|
|
atlas->setString(str);
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2012-03-22 18:29:07 +08:00
|
|
|
std::string ReorderParticleSystems::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "reorder systems";
|
2012-03-22 18:29:07 +08:00
|
|
|
}
|
|
|
|
|
2012-04-04 21:58:04 +08:00
|
|
|
std::string ReorderParticleSystems::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "changes every 2 seconds";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
2012-06-15 15:10:40 +08:00
|
|
|
|
|
|
|
// PremultipliedAlphaTest
|
|
|
|
|
2012-06-12 15:40:31 +08:00
|
|
|
std::string PremultipliedAlphaTest::title()
|
|
|
|
{
|
|
|
|
return "premultiplied alpha";
|
|
|
|
}
|
|
|
|
|
2012-06-15 15:10:40 +08:00
|
|
|
std::string PremultipliedAlphaTest::subtitle()
|
|
|
|
{
|
|
|
|
return "no black halo, particles should fade out";
|
|
|
|
}
|
|
|
|
|
|
|
|
void PremultipliedAlphaTest::onEnter()
|
|
|
|
{
|
|
|
|
ParticleDemo::onEnter();
|
|
|
|
|
2013-06-07 08:12:28 +08:00
|
|
|
m_color->setColor(ccBLUE);
|
2012-06-15 15:10:40 +08:00
|
|
|
this->removeChild(m_background, true);
|
|
|
|
m_background = NULL;
|
|
|
|
|
|
|
|
m_emitter = CCParticleSystemQuad::create("Particles/BoilingFoam.plist");
|
|
|
|
m_emitter->retain();
|
|
|
|
// Particle Designer "normal" blend func causes black halo on premul textures (ignores multiplication)
|
|
|
|
//this->emitter.blendFunc = (ccBlendFunc){ GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA };
|
|
|
|
|
|
|
|
// Cocos2d "normal" blend func for premul causes alpha to be ignored (oversaturates colors)
|
|
|
|
ccBlendFunc tBlendFunc = { GL_ONE, GL_ONE_MINUS_SRC_ALPHA };
|
|
|
|
m_emitter->setBlendFunc(tBlendFunc);
|
|
|
|
|
|
|
|
CCAssert(m_emitter->getOpacityModifyRGB(), "Particle texture does not have premultiplied alpha, test is useless");
|
|
|
|
|
|
|
|
// Toggle next line to see old behavior
|
|
|
|
// this->emitter.opacityModifyRGB = NO;
|
|
|
|
|
|
|
|
m_emitter->setStartColor(ccc4f(1, 1, 1, 1));
|
|
|
|
m_emitter->setEndColor(ccc4f(1, 1, 1, 0));
|
|
|
|
m_emitter->setStartColorVar(ccc4f(0, 0, 0, 0));
|
|
|
|
m_emitter->setEndColorVar(ccc4f(0, 0, 0, 0));
|
|
|
|
|
|
|
|
this->addChild(m_emitter, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
// PremultipliedAlphaTest2
|
|
|
|
|
|
|
|
void PremultipliedAlphaTest2::onEnter()
|
|
|
|
{
|
|
|
|
ParticleDemo::onEnter();
|
|
|
|
|
2013-06-07 08:12:28 +08:00
|
|
|
m_color->setColor(ccBLACK);
|
2012-06-15 15:10:40 +08:00
|
|
|
this->removeChild(m_background, true);
|
|
|
|
m_background = NULL;
|
|
|
|
|
|
|
|
m_emitter = CCParticleSystemQuad::create("Particles/TestPremultipliedAlpha.plist");
|
|
|
|
m_emitter->retain();
|
|
|
|
this->addChild(m_emitter ,10);
|
|
|
|
}
|
|
|
|
|
2012-06-12 15:40:31 +08:00
|
|
|
std::string PremultipliedAlphaTest2::title()
|
|
|
|
{
|
|
|
|
return "premultiplied alpha 2";
|
|
|
|
}
|
|
|
|
|
2012-06-15 15:10:40 +08:00
|
|
|
std::string PremultipliedAlphaTest2::subtitle()
|
|
|
|
{
|
|
|
|
return "Arrows should be faded";
|
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
void ParticleTestScene::runThisTest()
|
|
|
|
{
|
|
|
|
addChild(nextParticleAction());
|
|
|
|
|
|
|
|
CCDirector::sharedDirector()->replaceScene(this);
|
|
|
|
}
|