Merge pull request #5940 from boyu0/iss4513_particle_readd_bug

closed #4513: Particle doesn't animate when it was removed and re-added to another node.
This commit is contained in:
James Chen 2014-03-25 14:05:12 +08:00
commit 32f647d38b
4 changed files with 32 additions and 8 deletions

View File

@ -468,8 +468,6 @@ bool ParticleSystem::initWithTotalParticles(int numberOfParticles)
//updateParticleImp = (CC_UPDATE_PARTICLE_IMP) [self methodForSelector:updateParticleSel];
//for batchNode
_transformSystemDirty = false;
// update after action in run!
this->scheduleUpdateWithPriority(1);
return true;
}
@ -609,6 +607,14 @@ void ParticleSystem::initParticle(tParticle* particle)
}
}
void ParticleSystem::onEnter()
{
Node::onEnter();
// update after action in run!
this->scheduleUpdateWithPriority(1);
}
void ParticleSystem::stopSystem()
{
_isActive = false;

View File

@ -184,6 +184,7 @@ public:
//! whether or not the system is full
bool isFull();
virtual void onEnter();
//! should be overridden by subclasses
virtual void updateQuadWithParticle(tParticle* particle, const Point& newPosition);
//! should be overridden by subclasses

View File

@ -1828,12 +1828,26 @@ std::string ReorderParticleSystems::subtitle() const
std::string PremultipliedAlphaTest::title() const
{
return "premultiplied alpha";
return "premultiplied alpha and readd child test";
}
std::string PremultipliedAlphaTest::subtitle() const
{
return "no black halo, particles should fade out";
return "no black halo, particles should fade out\n animation should be normal";
}
void PremultipliedAlphaTest::readdPaticle(float delta)
{
static int count = 0;
if (count++ % 2 == 0)
{
_emitter->removeFromParent();
}
else
{
this->addChild(_emitter);
}
}
void PremultipliedAlphaTest::onEnter()
@ -1857,12 +1871,14 @@ void PremultipliedAlphaTest::onEnter()
// Toggle next line to see old behavior
// this->emitter.opacityModifyRGB = NO;
_emitter->setStartColor(Color4F(1, 1, 1, 1));
_emitter->setEndColor(Color4F(1, 1, 1, 0));
_emitter->setStartColorVar(Color4F(0, 0, 0, 0));
_emitter->setEndColorVar(Color4F(0, 0, 0, 0));
_emitter->setStartColor(Color4F(1.0f, 1.0f, 1.0f, 1.0f));
_emitter->setEndColor(Color4F(1.0f, 1.0f, 1.0f, 0.0f));
_emitter->setStartColorVar(Color4F(0.0f, 0.0f, 0.0f, 0.0f));
_emitter->setEndColorVar(Color4F(0.0f, 0.0f, 0.0f, 0.0f));
this->addChild(_emitter, 10);
schedule(schedule_selector(PremultipliedAlphaTest::readdPaticle), 1.0f);
}
// PremultipliedAlphaTest2

View File

@ -289,6 +289,7 @@ class PremultipliedAlphaTest : public ParticleDemo
{
public:
virtual void onEnter() override;
void readdPaticle(float delta);
virtual std::string title() const override;
virtual std::string subtitle() const override;
};