Particle.h
#ifndef? _Particle_
# Definition? _Particle_
# Contains? " cocos2d.h "
classParticleBoma? :? Public? cocos2d::CCParticleSystemQuad
{
Public:
particle boma();
Virtual? ~ particle boma();
Bull? init();
//Virtual function defined in //cocos
Virtual? Bull? InitWithTotalParticles (unsigned? int? number of particles);
Static electricity particle boma * create();
Static electricity ParticleBoma? * node();
Protected:
Private:
};
#endif
Particle. cpp
# Contains? " Particle.h "
Use _ NS _ CC
ParticleBoma::ParticleBoma()
{
}
ParticleBoma::~ParticleBoma()
{
}
Bull? ParticleBoma::init()
{
Return? initWithTotalParticles( 1500);
}
//Some methods to realize initialization
Bull? particle boma::initWithTotalParticles(? Not signed? int? numberofParticles? )
{
If (? CCParticleSystemQuad::initWithTotalParticles(number of particles)? )
{
//? Duration? Set the time for this particle effect. If it is set to kCCParticleDurationInfinity, it means that the particle effect is eternal, and its timing unit is seconds.
m_fDuration? = 0.3f
//? Gravity? way
m_nEmitterMode? =? kCCParticleModeGravity
//? Gravity? Mode:? gravity
ModeA. gravity? =? ccp(0,0);
//? Gravity? Mode:? Defines the emission speed of particles.
Models. Speed? =? 80;
modeA.speedVar? =? 0;
//? Gravity? Mode:? Set radial acceleration
modeA.radialAccel? =? 0;
modeA.radialAccelVar? =? 0;
//? Gravity? Mode:? Set tangential acceleration
modeA.tangentialAccel? =? 0;
modeA.tangentialAccelVar? =? 0;
//? corner
Is it square? =? 180;
m_fAngleVar? =? 360;
//? Transmitter? location
CCSize? winSize? =? cc director::shared director()-& gt; getWinSize();
This-> set position(CCP(winsize . width/2,winsize . height/2));
m_tPosVar? =? CCPointZero
//? Life? Yes? Particles? Length of life cycle
m_fLife? =? 2;
m_fLifeVar? =? 1;
//? Size? Are you online? The following two sentences of pixel mean that the size of particles when they first appear is randomly generated between 20.0f and 30.0f F.
m_fStartSize? =? 20.0f
m_fStartSizeVar? =? 10.0 f;
m_fEndSize? =? kCCParticleStartSizeEqualToEndSize;
//? Distribute per? second
m_fEmissionRate? =? m _ uTotalParticles/m _ fLife;
//? Color? Yes? Particles set the initial color of particles and the color evolution process at the end.
m_tStartColor.r? =? 0.00f
m_tStartColor.g? =? 1.00 f;
m_tStartColor.b? =? 0.00f
m_tStartColor.a? =? 1.0f;
m_tStartColorVar.r? =? 1.0f;
m_tStartColorVar.g? =? 1.0f;
m_tStartColorVar.b? =? 0.0f
m_tStartColorVar.a? =? 1.0f;
m_tEndColor.r? =? 0.0f
m_tEndColor.g? =? 0.0f
m_tEndColor.b? =? 0.0f
m_tEndColor.a? =? 0.0 1f;
m_tEndColorVar.r? =? 0.0f
m_tEndColorVar.g? =? 0.0f
m_tEndColorVar.b? =? 0.0f
m_tEndColorVar.a? =? 0.0f
//? additive
This-> setblendeditive(true);
Return? True;
}
Return? Fake;
}
ParticleBoma? *ParticleBoma::create()
{
ParticleBoma? *? particleBoma? =? New? particle boma();
What if? (particle boma-& gt; init())
{
particle boma-& gt; autorelease();
Return? particleBoma
}
CC _ SAFE _ DELETE(particle boma);
Return? NULL
}
ParticleBoma? *? ParticleBoma::node()
{
Return? create();
}
Then we can use this particle effect in the HelloWorldScene.cpp file.
Invalid? HelloWorld::onEnter()
{
cc layer::onEnter();
Replay (empty);
}
//The main methods of waste
Invalid? HelloWorld::Replay(CCObject*? pSender)
{
m_emitter? =? particle boma::create();
m _ emitter->; retain();
This-> addChild(m_emitter, 10);
m _ emitter->; set texture(CCTextureCache::sharedTextureCache()-& gt; addImage(" 16 . png ");
//This particle effect can be partially set. Above or below CPP. If the set method is used below, the value is set to partial. CPP will be overwritten.
m _ emitter->; setLifeVar(0);
//Sets the life cycle length of particles in seconds.
m _ emitter->; setLife( 1.0f);
m _ emitter->; set speed( 100);
m _ emitter->; setSpeedVar(40);
//The emissivity of particles? Per second 1000
m _ emitter->; setEmissionRate( 1000);
CCSize? Size? =? cc director::shared director()-& gt; getWinSize();
m _ emitter->; SetPosition(ccp (size width /2, size height/2));
}