mirror of https://github.com/axmolengine/axmol.git
Merge pull request #7609 from boyu0/bug5762_setTotalParticles
Closed #5762: ParticleSystemQuad::setTotalParticles() can't set a value larger than the initialized value.
This commit is contained in:
commit
52dfb7224e
|
@ -449,6 +449,10 @@ void ParticleSystemQuad::setTotalParticles(int tp)
|
|||
_totalParticles = tp;
|
||||
}
|
||||
|
||||
// fixed issue #5762
|
||||
// reset the emission rate
|
||||
setEmissionRate(_totalParticles / _life);
|
||||
|
||||
resetSystem();
|
||||
}
|
||||
|
||||
|
|
|
@ -1012,13 +1012,14 @@ Layer* createParticleLayer(int nIndex)
|
|||
case 46: return new Issue3990();
|
||||
case 47: return new ParticleAutoBatching();
|
||||
case 48: return new ParticleVisibleTest();
|
||||
case 49: return new ParticleResetTotalParticles();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
#define MAX_LAYER 49
|
||||
#define MAX_LAYER 50
|
||||
|
||||
|
||||
Layer* nextParticleAction()
|
||||
|
@ -2005,6 +2006,52 @@ std::string ParticleAutoBatching::subtitle() const
|
|||
return "All 10 particles should be drawin in one batch";
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// ParticleResetTotalParticles
|
||||
//
|
||||
void ParticleResetTotalParticles::onEnter()
|
||||
{
|
||||
ParticleDemo::onEnter();
|
||||
|
||||
_color->setColor(Color3B::BLACK);
|
||||
removeChild(_background, true);
|
||||
_background = nullptr;
|
||||
|
||||
auto p = ParticleFire::createWithTotalParticles(10);
|
||||
this->addChild(p);
|
||||
|
||||
auto add = MenuItemFont::create("add 10 particles",
|
||||
[p](Ref*)->void
|
||||
{
|
||||
p->setTotalParticles(p->getTotalParticles() + 10 );
|
||||
});
|
||||
add->setPosition(Vec2(0, 25));
|
||||
auto remove = MenuItemFont::create("remove 10 particles",
|
||||
[p](Ref*)->void
|
||||
{
|
||||
int count = p->getTotalParticles() - 10;
|
||||
if (count < 0) { count = 0; }
|
||||
p->setTotalParticles(count);
|
||||
});
|
||||
remove->setPosition(Vec2(0, -25));
|
||||
|
||||
auto menu = Menu::create(add, remove, nullptr);
|
||||
menu->setPosition(Vec2(VisibleRect::center()));
|
||||
this->addChild(menu);
|
||||
|
||||
}
|
||||
|
||||
std::string ParticleResetTotalParticles::title() const
|
||||
{
|
||||
return "reset total particles";
|
||||
}
|
||||
|
||||
std::string ParticleResetTotalParticles::subtitle() const
|
||||
{
|
||||
return "it should work as well";
|
||||
}
|
||||
|
||||
//
|
||||
// main
|
||||
//
|
||||
|
|
|
@ -328,4 +328,12 @@ public:
|
|||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class ParticleResetTotalParticles : public ParticleDemo
|
||||
{
|
||||
public:
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue