3.10 CCParticleSystem.cpp
void ParticleSystem::update(float dt)
{
…
{
for (int i = 0; i < _particleCount; ++i)
{
_particleData.timeToLive* -= dt;
}
for (int i = 0; i < _particleCount; ++i)
{
if (_particleData.timeToLive* <= 0.0f)
{
int j = _particleCount - 1;
while (j > 0 && _particleData.timeToLive <= 0)
{
_particleCount--;
j--;
}
_particleData.copyParticle(i, _particleCount - 1);
if (_batchNode)
{
//disable the switched particle
int currentIndex = _particleData.atlasIndex*;
_batchNode->disableParticle(_atlasIndex + currentIndex);
//switch indexes
_particleData.atlasIndex = currentIndex;
}
--_particleCount;
if( _particleCount == 0 && _isAutoRemoveOnFinish )
{
this->unscheduleUpdate();
_parent->removeChild(this, true);
return;
}
}
}
if (_emitterMode == Mode::GRAVITY)
{
for (int i = 0 ; i < _particleCount; ++i)**
{
particle_point tmp, radial = {0.0f, 0.0f}, tangential;
// radial acceleration
if (_particleData.posx* || _particleData.posy*)
{
nomalize_point(_particleData.posx*, _particleData.posy*, &radial);
}
tangential = radial;
radial.x *= _particleData.modeA.radialAccel*;
radial.y *= _particleData.modeA.radialAccel*;
// tangential acceleration
std::swap(tangential.x, tangential.y);
tangential.x *= - _particleData.modeA.tangentialAccel*;
tangential.y *= _particleData.modeA.tangentialAccel*;
// (gravity + radial + tangential) * dt
tmp.x = radial.x + tangential.x + modeA.gravity.x;
tmp.y = radial.y + tangential.y + modeA.gravity.y;
tmp.x *= dt;
tmp.y *= dt;
_particleData.modeA.dirX* += tmp.x;
_particleData.modeA.dirY* += tmp.y;
// this is cocos2d-x v3.0
// if (_configName.length()>0 && _yCoordFlipped != -1)
// this is cocos2d-x v3.0
tmp.x = _particleData.modeA.dirX* * dt * _yCoordFlipped;
tmp.y = _particleData.modeA.dirY* * dt * _yCoordFlipped;
_particleData.posx* += tmp.x;
_particleData.posy* += tmp.y;
}
}
else
{
for (int i = 0; i < _particleCount; ++i)**************
{
_particleData.modeB.angle* += _particleData.modeB.degreesPerSecond* * dt;
}
for (int i = 0; i < _particleCount; ++i)**
{
_particleData.modeB.radius* += _particleData.modeB.deltaRadius* * dt;
}
for (int i = 0; i < _particleCount; ++i)**
{
_particleData.posx* = - cosf(_particleData.modeB.angle*) * _particleData.modeB.radius*;
}
for (int i = 0; i < _particleCount; ++i)***
{
_particleData.posy* = - sinf(_particleData.modeB.angle*) * _particleData.modeB.radius* * _yCoordFlipped;
}
}
//color r,g,b,a
for (int i = 0 ; i < _particleCount; ++i)***
{
_particleData.colorR* += _particleData.deltaColorR* * dt;
}
for (int i = 0 ; i < _particleCount; ++i)**
{
_particleData.colorG* += _particleData.deltaColorG* * dt;
}
for (int i = 0 ; i < _particleCount; ++i)**
{
_particleData.colorB* += _particleData.deltaColorB* * dt;
}
for (int i = 0 ; i < _particleCount; ++i)**
{
_particleData.colorA* += _particleData.deltaColorA* * dt;
}
//size
for (int i = 0 ; i < _particleCount; ++i)**
{
_particleData.size* += (_particleData.deltaSize* * dt);
_particleData.size* = MAX(0, _particleData.size*);
}
//angle
for (int i = 0 ; i < _particleCount; ++i)****
{
_particleData.rotation* += _particleData.deltaRotation* * dt;
}
updateParticleQuads();
_transformSystemDirty = false;
}
…
}