mirror of https://github.com/axmolengine/axmol.git
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:
parent
8c9019b128
commit
7214173e98
|
@ -588,6 +588,8 @@ ParticleSystem::~ParticleSystem()
|
||||||
|
|
||||||
void ParticleSystem::addParticles(int count)
|
void ParticleSystem::addParticles(int count)
|
||||||
{
|
{
|
||||||
|
if (_paused)
|
||||||
|
return;
|
||||||
uint32_t RANDSEED = rand();
|
uint32_t RANDSEED = rand();
|
||||||
|
|
||||||
int start = _particleCount;
|
int start = _particleCount;
|
||||||
|
@ -1348,4 +1350,22 @@ void ParticleSystem::stop()
|
||||||
{
|
{
|
||||||
stopSystem();
|
stopSystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ParticleSystem::isPaused() const
|
||||||
|
{
|
||||||
|
return _paused;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParticleSystem::pauseEmissions()
|
||||||
|
{
|
||||||
|
_paused = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParticleSystem::resumeEmissions()
|
||||||
|
{
|
||||||
|
_paused = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -801,6 +801,17 @@ CC_CONSTRUCTOR_ACCESS:
|
||||||
|
|
||||||
//! Initializes a system with a fixed number of particles
|
//! Initializes a system with a fixed number of particles
|
||||||
virtual bool initWithTotalParticles(int numberOfParticles);
|
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:
|
protected:
|
||||||
virtual void updateBlendFunc();
|
virtual void updateBlendFunc();
|
||||||
|
@ -956,6 +967,9 @@ protected:
|
||||||
@since v0.8
|
@since v0.8
|
||||||
*/
|
*/
|
||||||
PositionType _positionType;
|
PositionType _positionType;
|
||||||
|
|
||||||
|
/** is the emitter paused */
|
||||||
|
bool _paused;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CC_DISALLOW_COPY_AND_ASSIGN(ParticleSystem);
|
CC_DISALLOW_COPY_AND_ASSIGN(ParticleSystem);
|
||||||
|
|
|
@ -705,5 +705,4 @@ std::string ParticleSystemQuad::getDescription() const
|
||||||
{
|
{
|
||||||
return StringUtils::format("<ParticleSystemQuad | Tag = %d, Total Particles = %d>", _tag, _totalParticles);
|
return StringUtils::format("<ParticleSystemQuad | Tag = %d, Total Particles = %d>", _tag, _totalParticles);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -161,6 +161,8 @@ CC_CONSTRUCTOR_ACCESS:
|
||||||
* @lua NA
|
* @lua NA
|
||||||
*/
|
*/
|
||||||
virtual bool initWithTotalParticles(int numberOfParticles) override;
|
virtual bool initWithTotalParticles(int numberOfParticles) override;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** initializes the indices for the vertices*/
|
/** initializes the indices for the vertices*/
|
||||||
|
@ -182,6 +184,8 @@ protected:
|
||||||
GLuint _buffersVBO[2]; //0: vertex 1: indices
|
GLuint _buffersVBO[2]; //0: vertex 1: indices
|
||||||
|
|
||||||
QuadCommand _quadCommand; // quad command
|
QuadCommand _quadCommand; // quad command
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CC_DISALLOW_COPY_AND_ASSIGN(ParticleSystemQuad);
|
CC_DISALLOW_COPY_AND_ASSIGN(ParticleSystemQuad);
|
||||||
|
|
|
@ -80,6 +80,43 @@ std::string DemoSun::subtitle() const
|
||||||
return "ParticleSun";
|
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
|
// DemoGalaxy
|
||||||
|
@ -976,6 +1013,7 @@ ParticleTests::ParticleTests()
|
||||||
ADD_TEST_CASE(DemoModernArt);
|
ADD_TEST_CASE(DemoModernArt);
|
||||||
ADD_TEST_CASE(DemoRing);
|
ADD_TEST_CASE(DemoRing);
|
||||||
ADD_TEST_CASE(ParallaxParticle);
|
ADD_TEST_CASE(ParallaxParticle);
|
||||||
|
ADD_TEST_CASE(DemoPause);
|
||||||
addTestCase("BoilingFoam", [](){return DemoParticleFromFile::create("BoilingFoam");});
|
addTestCase("BoilingFoam", [](){return DemoParticleFromFile::create("BoilingFoam");});
|
||||||
addTestCase("BurstPipe", [](){return DemoParticleFromFile::create("BurstPipe"); });
|
addTestCase("BurstPipe", [](){return DemoParticleFromFile::create("BurstPipe"); });
|
||||||
addTestCase("Comet", [](){return DemoParticleFromFile::create("Comet"); });
|
addTestCase("Comet", [](){return DemoParticleFromFile::create("Comet"); });
|
||||||
|
|
|
@ -380,4 +380,13 @@ public:
|
||||||
virtual std::string subtitle() const override;
|
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
|
#endif
|
||||||
|
|
|
@ -135,6 +135,9 @@ var particleSceneArr = [
|
||||||
},
|
},
|
||||||
function() {
|
function() {
|
||||||
return new ParticleResizeTest();
|
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({
|
var DemoGalaxy = ParticleDemo.extend({
|
||||||
onEnter:function () {
|
onEnter:function () {
|
||||||
this._super();
|
this._super();
|
||||||
|
|
|
@ -471,6 +471,24 @@ local function DemoSun()
|
||||||
return layer
|
return layer
|
||||||
end
|
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
|
-- DemoMeteor
|
||||||
---------------------------------
|
---------------------------------
|
||||||
|
@ -1489,6 +1507,8 @@ function CreateParticleLayer()
|
||||||
elseif SceneIdx == 40 then return ReorderParticleSystems()
|
elseif SceneIdx == 40 then return ReorderParticleSystems()
|
||||||
elseif SceneIdx == 41 then return PremultipliedAlphaTest()
|
elseif SceneIdx == 41 then return PremultipliedAlphaTest()
|
||||||
elseif SceneIdx == 42 then return PremultipliedAlphaTest2()
|
elseif SceneIdx == 42 then return PremultipliedAlphaTest2()
|
||||||
|
elseif SceneIdx == 43 then return DemoPause()
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue