Added Particle Emitter Pause option, and tests (#15836)

* Added Particle Emitter Pause option, and tests

* private field emitter => _emitter
isPaused changed to const
removed erroneously added spaces
renamed unPauseEmissions => resumeEmissions
This commit is contained in:
PooperPig 2016-06-15 20:31:10 +10:00 committed by minggo
parent 8c9019b128
commit 7214173e98
8 changed files with 125 additions and 1 deletions

View File

@ -588,6 +588,8 @@ ParticleSystem::~ParticleSystem()
void ParticleSystem::addParticles(int count)
{
if (_paused)
return;
uint32_t RANDSEED = rand();
int start = _particleCount;
@ -1348,4 +1350,22 @@ void ParticleSystem::stop()
{
stopSystem();
}
bool ParticleSystem::isPaused() const
{
return _paused;
}
void ParticleSystem::pauseEmissions()
{
_paused = true;
}
void ParticleSystem::resumeEmissions()
{
_paused = false;
}
NS_CC_END

View File

@ -802,6 +802,17 @@ CC_CONSTRUCTOR_ACCESS:
//! Initializes a system with a fixed number of particles
virtual bool initWithTotalParticles(int numberOfParticles);
/** Are the emissions paused
@return True if the emissions are paused, else false
*/
virtual bool isPaused() const;
/* Pause the emissions*/
virtual void pauseEmissions();
/* UnPause the emissions*/
virtual void resumeEmissions();
protected:
virtual void updateBlendFunc();
@ -957,6 +968,9 @@ protected:
*/
PositionType _positionType;
/** is the emitter paused */
bool _paused;
private:
CC_DISALLOW_COPY_AND_ASSIGN(ParticleSystem);
};

View File

@ -705,5 +705,4 @@ std::string ParticleSystemQuad::getDescription() const
{
return StringUtils::format("<ParticleSystemQuad | Tag = %d, Total Particles = %d>", _tag, _totalParticles);
}
NS_CC_END

View File

@ -162,6 +162,8 @@ CC_CONSTRUCTOR_ACCESS:
*/
virtual bool initWithTotalParticles(int numberOfParticles) override;
protected:
/** initializes the indices for the vertices*/
void initIndices();
@ -183,6 +185,8 @@ protected:
QuadCommand _quadCommand; // quad command
private:
CC_DISALLOW_COPY_AND_ASSIGN(ParticleSystemQuad);
};

View File

@ -80,6 +80,43 @@ std::string DemoSun::subtitle() const
return "ParticleSun";
}
//------------------------------------------------------------------
//
// DemoPause
//
//------------------------------------------------------------------
void DemoPause::onEnter()
{
ParticleDemo::onEnter();
_emitter = ParticleSmoke::create();
_emitter->retain();
_background->addChild(_emitter, 10);
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_fire) );
setEmitterPosition();
schedule(CC_SCHEDULE_SELECTOR(DemoPause::pauseEmitter), 2.0f);
}
void DemoPause::pauseEmitter(float time)
{
if (_emitter->isPaused())
{
_emitter->resumeEmissions();
}
else
{
_emitter->pauseEmissions();
}
}
std::string DemoPause::subtitle() const
{
return "Pause Particle";
}
//------------------------------------------------------------------
//
// DemoGalaxy
@ -976,6 +1013,7 @@ ParticleTests::ParticleTests()
ADD_TEST_CASE(DemoModernArt);
ADD_TEST_CASE(DemoRing);
ADD_TEST_CASE(ParallaxParticle);
ADD_TEST_CASE(DemoPause);
addTestCase("BoilingFoam", [](){return DemoParticleFromFile::create("BoilingFoam");});
addTestCase("BurstPipe", [](){return DemoParticleFromFile::create("BurstPipe"); });
addTestCase("Comet", [](){return DemoParticleFromFile::create("Comet"); });

View File

@ -380,4 +380,13 @@ public:
virtual std::string subtitle() const override;
};
class DemoPause : public ParticleDemo
{
public:
CREATE_FUNC(DemoPause);
virtual void onEnter() override;
virtual std::string subtitle() const override;
void pauseEmitter(float time);
};
#endif

View File

@ -135,6 +135,9 @@ var particleSceneArr = [
},
function() {
return new ParticleResizeTest();
},
function() {
return new DemoPause();
}
];
@ -432,6 +435,23 @@ var DemoSun = ParticleDemo.extend({
}
});
var DemoPause = ParticleDemo.extend({
onEnter:function () {
this._super();
this._emitter = new cc.ParticleSmoke();
this._background.addChild(this._emitter, 10);
this._emitter.texture = cc.textureCache.addImage(s_fire);
if (this._emitter.setShapeType)
this._emitter.setShapeType(cc.ParticleSystem.BALL_SHAPE);
this.setEmitterPosition();
},
title:function () {
return "Pause Particle";
}
});
var DemoGalaxy = ParticleDemo.extend({
onEnter:function () {
this._super();

View File

@ -471,6 +471,24 @@ local function DemoSun()
return layer
end
---------------------------------
-- DemoPause
---------------------------------
local function DemoPause()
local layer = getBaseLayer()
emitter = cc.ParticleSmoke:create()
-- emitter:retain()
background:addChild(emitter, 10)
emitter:setTexture(cc.Director:getInstance():getTextureCache():addImage(s_fire))
setEmitterPosition()
titleLabel:setString("Pasue Particle")
return layer
end
---------------------------------
-- DemoMeteor
---------------------------------
@ -1489,6 +1507,8 @@ function CreateParticleLayer()
elseif SceneIdx == 40 then return ReorderParticleSystems()
elseif SceneIdx == 41 then return PremultipliedAlphaTest()
elseif SceneIdx == 42 then return PremultipliedAlphaTest2()
elseif SceneIdx == 43 then return DemoPause()
end
end