diff --git a/cocos/2d/CCParticleSystem.cpp b/cocos/2d/CCParticleSystem.cpp index 1b33f87063..f3c62972fb 100644 --- a/cocos/2d/CCParticleSystem.cpp +++ b/cocos/2d/CCParticleSystem.cpp @@ -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 diff --git a/cocos/2d/CCParticleSystem.h b/cocos/2d/CCParticleSystem.h index f4b8f87617..b3d6d2c96f 100644 --- a/cocos/2d/CCParticleSystem.h +++ b/cocos/2d/CCParticleSystem.h @@ -801,6 +801,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(); @@ -956,6 +967,9 @@ protected: @since v0.8 */ PositionType _positionType; + + /** is the emitter paused */ + bool _paused; private: CC_DISALLOW_COPY_AND_ASSIGN(ParticleSystem); diff --git a/cocos/2d/CCParticleSystemQuad.cpp b/cocos/2d/CCParticleSystemQuad.cpp index c840124df6..b1ddc49f7d 100644 --- a/cocos/2d/CCParticleSystemQuad.cpp +++ b/cocos/2d/CCParticleSystemQuad.cpp @@ -705,5 +705,4 @@ std::string ParticleSystemQuad::getDescription() const { return StringUtils::format("", _tag, _totalParticles); } - NS_CC_END diff --git a/cocos/2d/CCParticleSystemQuad.h b/cocos/2d/CCParticleSystemQuad.h index 2cc88c9616..825e2aed2b 100644 --- a/cocos/2d/CCParticleSystemQuad.h +++ b/cocos/2d/CCParticleSystemQuad.h @@ -161,6 +161,8 @@ CC_CONSTRUCTOR_ACCESS: * @lua NA */ virtual bool initWithTotalParticles(int numberOfParticles) override; + + protected: /** initializes the indices for the vertices*/ @@ -182,6 +184,8 @@ protected: GLuint _buffersVBO[2]; //0: vertex 1: indices QuadCommand _quadCommand; // quad command + + private: CC_DISALLOW_COPY_AND_ASSIGN(ParticleSystemQuad); diff --git a/tests/cpp-tests/Classes/ParticleTest/ParticleTest.cpp b/tests/cpp-tests/Classes/ParticleTest/ParticleTest.cpp index 104b8e1c4b..2fb5d51839 100644 --- a/tests/cpp-tests/Classes/ParticleTest/ParticleTest.cpp +++ b/tests/cpp-tests/Classes/ParticleTest/ParticleTest.cpp @@ -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"); }); diff --git a/tests/cpp-tests/Classes/ParticleTest/ParticleTest.h b/tests/cpp-tests/Classes/ParticleTest/ParticleTest.h index a7c5a8cbba..235b8ec783 100644 --- a/tests/cpp-tests/Classes/ParticleTest/ParticleTest.h +++ b/tests/cpp-tests/Classes/ParticleTest/ParticleTest.h @@ -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 diff --git a/tests/js-tests/src/ParticleTest/ParticleTest.js b/tests/js-tests/src/ParticleTest/ParticleTest.js index 6ca5443e72..da6f5c5cfe 100644 --- a/tests/js-tests/src/ParticleTest/ParticleTest.js +++ b/tests/js-tests/src/ParticleTest/ParticleTest.js @@ -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(); diff --git a/tests/lua-tests/src/ParticleTest/ParticleTest.lua b/tests/lua-tests/src/ParticleTest/ParticleTest.lua index cb16737622..cbb76b8dfc 100644 --- a/tests/lua-tests/src/ParticleTest/ParticleTest.lua +++ b/tests/lua-tests/src/ParticleTest/ParticleTest.lua @@ -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