2018-01-29 16:25:32 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-04-04 21:58:04 +08:00
|
|
|
#include "ParticleTest.h"
|
|
|
|
#include "../testResource.h"
|
2020-10-17 16:32:16 +08:00
|
|
|
#include "libeditor/CocosStudioExtension.h"
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
|
2012-04-04 21:58:04 +08:00
|
|
|
enum {
|
2012-04-19 14:35:52 +08:00
|
|
|
kTagParticleCount = 1,
|
2012-04-04 21:58:04 +08:00
|
|
|
};
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoFirework
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoFirework::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
_emitter = ParticleFireworks::create();
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->retain();
|
|
|
|
_background->addChild(_emitter, 10);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-11-07 21:48:39 +08:00
|
|
|
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_stars1) );
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string DemoFirework::subtitle() const
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ParticleFireworks";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoFire
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoFire::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
_emitter = ParticleFire::create();
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->retain();
|
|
|
|
_background->addChild(_emitter, 10);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-11-07 21:48:39 +08:00
|
|
|
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_fire) );//.pvr");
|
2013-08-16 16:05:27 +08:00
|
|
|
auto p = _emitter->getPosition();
|
2019-09-24 11:31:35 +08:00
|
|
|
_emitter->setPosition( Vec2(p.x, 100.0f) );
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string DemoFire::subtitle() const
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ParticleFire";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoSun
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoSun::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
_emitter = ParticleSun::create();
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->retain();
|
|
|
|
_background->addChild(_emitter, 10);
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2013-11-07 21:48:39 +08:00
|
|
|
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_fire) );
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string DemoSun::subtitle() const
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ParticleSun";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2016-06-15 18:31:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// 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";
|
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoGalaxy
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoGalaxy::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
_emitter = ParticleGalaxy::create();
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->retain();
|
|
|
|
_background->addChild(_emitter, 10);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-11-07 21:48:39 +08:00
|
|
|
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_fire) );
|
2013-11-30 01:09:38 +08:00
|
|
|
|
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string DemoGalaxy::subtitle() const
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ParticleGalaxy";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoFlower
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoFlower::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
_emitter = ParticleFlower::create();
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->retain();
|
|
|
|
_background->addChild(_emitter, 10);
|
2013-11-07 21:48:39 +08:00
|
|
|
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_stars1) );
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string DemoFlower::subtitle() const
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ParticleFlower";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoBigFlower
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoBigFlower::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-11-15 08:21:49 +08:00
|
|
|
_emitter = ParticleSystemQuad::createWithTotalParticles(50);
|
|
|
|
_emitter->retain();
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_background->addChild(_emitter, 10);
|
|
|
|
////_emitter->release(); // win32 : use this line or remove this line and use autorelease()
|
2013-11-07 21:48:39 +08:00
|
|
|
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_stars1) );
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setDuration(-1);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// gravity
|
2014-05-15 01:07:09 +08:00
|
|
|
_emitter->setGravity(Vec2::ZERO);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// angle
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setAngle(90);
|
|
|
|
_emitter->setAngleVar(360);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// speed of particles
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setSpeed(160);
|
|
|
|
_emitter->setSpeedVar(20);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// radial
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setRadialAccel(-120);
|
|
|
|
_emitter->setRadialAccelVar(0);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2017-02-10 10:35:52 +08:00
|
|
|
// tangential
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setTangentialAccel(30);
|
|
|
|
_emitter->setTangentialAccelVar(0);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// emitter position
|
2014-05-15 01:07:09 +08:00
|
|
|
_emitter->setPosition( Vec2(160,240) );
|
|
|
|
_emitter->setPosVar(Vec2::ZERO);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// life of particles
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setLife(4);
|
|
|
|
_emitter->setLifeVar(1);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// spin of particles
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartSpin(0);
|
|
|
|
_emitter->setStartSizeVar(0);
|
|
|
|
_emitter->setEndSpin(0);
|
|
|
|
_emitter->setEndSpinVar(0);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// color of particles
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F startColor(0.5f, 0.5f, 0.5f, 1.0f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartColor(startColor);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F startColorVar(0.5f, 0.5f, 0.5f, 1.0f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartColorVar(startColorVar);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F endColor(0.1f, 0.1f, 0.1f, 0.2f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setEndColor(endColor);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
|
|
|
Color4F endColorVar(0.1f, 0.1f, 0.1f, 0.2f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setEndColorVar(endColorVar);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// size, in pixels
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartSize(80.0f);
|
|
|
|
_emitter->setStartSizeVar(40.0f);
|
2013-07-25 14:27:46 +08:00
|
|
|
_emitter->setEndSize(ParticleSystem::START_SIZE_EQUAL_TO_END_SIZE);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// emits per second
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setEmissionRate(_emitter->getTotalParticles()/_emitter->getLife());
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// additive
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setBlendAdditive(true);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string DemoBigFlower::subtitle() const
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ParticleBigFlower";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoRotFlower
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoRotFlower::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
|
|
|
|
2013-11-15 08:21:49 +08:00
|
|
|
_emitter = ParticleSystemQuad::createWithTotalParticles(300);
|
|
|
|
_emitter->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_background->addChild(_emitter, 10);
|
|
|
|
////_emitter->release(); // win32 : Remove this line
|
2013-11-07 21:48:39 +08:00
|
|
|
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_stars2) );
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// duration
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setDuration(-1);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// gravity
|
2014-05-15 01:07:09 +08:00
|
|
|
_emitter->setGravity(Vec2::ZERO);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// angle
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setAngle(90);
|
|
|
|
_emitter->setAngleVar(360);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// speed of particles
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setSpeed(160);
|
|
|
|
_emitter->setSpeedVar(20);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// radial
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setRadialAccel(-120);
|
|
|
|
_emitter->setRadialAccelVar(0);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2017-02-10 10:35:52 +08:00
|
|
|
// tangential
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setTangentialAccel(30);
|
|
|
|
_emitter->setTangentialAccelVar(0);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// emitter position
|
2014-05-15 01:07:09 +08:00
|
|
|
_emitter->setPosition( Vec2(160,240) );
|
|
|
|
_emitter->setPosVar(Vec2::ZERO);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// life of particles
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setLife(3);
|
|
|
|
_emitter->setLifeVar(1);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// spin of particles
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartSpin(0);
|
|
|
|
_emitter->setStartSpinVar(0);
|
|
|
|
_emitter->setEndSpin(0);
|
|
|
|
_emitter->setEndSpinVar(2000);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// color of particles
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F startColor(0.5f, 0.5f, 0.5f, 1.0f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartColor(startColor);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F startColorVar(0.5f, 0.5f, 0.5f, 1.0f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartColorVar(startColorVar);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F endColor(0.1f, 0.1f, 0.1f, 0.2f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setEndColor(endColor);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
|
|
|
Color4F endColorVar(0.1f, 0.1f, 0.1f, 0.2f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setEndColorVar(endColorVar);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// size, in pixels
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartSize(30.0f);
|
|
|
|
_emitter->setStartSizeVar(00.0f);
|
2013-07-25 14:27:46 +08:00
|
|
|
_emitter->setEndSize(ParticleSystem::START_SIZE_EQUAL_TO_END_SIZE);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// emits per second
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setEmissionRate(_emitter->getTotalParticles()/_emitter->getLife());
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// additive
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setBlendAdditive(false);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string DemoRotFlower::subtitle() const
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ParticleRotFlower";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoMeteor
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoMeteor::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
_emitter = ParticleMeteor::create();
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->retain();
|
|
|
|
_background->addChild(_emitter, 10);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-11-07 21:48:39 +08:00
|
|
|
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_fire) );
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string DemoMeteor::subtitle() const
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ParticleMeteor";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoSpiral
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoSpiral::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
_emitter = ParticleSpiral::create();
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->retain();
|
|
|
|
_background->addChild(_emitter, 10);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-11-07 21:48:39 +08:00
|
|
|
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_fire) );
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string DemoSpiral::subtitle() const
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ParticleSpiral";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoExplosion
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoExplosion::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
_emitter = ParticleExplosion::create();
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->retain();
|
|
|
|
_background->addChild(_emitter, 10);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-11-07 21:48:39 +08:00
|
|
|
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_stars1) );
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setAutoRemoveOnFinish(true);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string DemoExplosion::subtitle() const
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ParticleExplosion";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoSmoke
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoSmoke::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
_emitter = ParticleSmoke::create();
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->retain();
|
|
|
|
_background->addChild(_emitter, 10);
|
2013-11-07 21:48:39 +08:00
|
|
|
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_fire) );
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto p = _emitter->getPosition();
|
2019-09-24 11:31:35 +08:00
|
|
|
_emitter->setPosition( Vec2( p.x, 100.0f) );
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string DemoSmoke::subtitle() const
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ParticleSmoke";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoSnow
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoSnow::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
_emitter = ParticleSnow::create();
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->retain();
|
|
|
|
_background->addChild(_emitter, 10);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto p = _emitter->getPosition();
|
2014-05-15 01:07:09 +08:00
|
|
|
_emitter->setPosition( Vec2( p.x, p.y-110) );
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setLife(3);
|
|
|
|
_emitter->setLifeVar(1);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// gravity
|
2019-09-24 11:31:35 +08:00
|
|
|
_emitter->setGravity(Vec2(0.0f,-10.0f));
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// speed of particles
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setSpeed(130);
|
|
|
|
_emitter->setSpeedVar(30);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
Color4F startColor = _emitter->getStartColor();
|
2012-04-19 14:35:52 +08:00
|
|
|
startColor.r = 0.9f;
|
|
|
|
startColor.g = 0.9f;
|
|
|
|
startColor.b = 0.9f;
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartColor(startColor);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
Color4F startColorVar = _emitter->getStartColorVar();
|
2012-04-19 14:35:52 +08:00
|
|
|
startColorVar.b = 0.1f;
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartColorVar(startColorVar);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setEmissionRate(_emitter->getTotalParticles()/_emitter->getLife());
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-11-07 21:48:39 +08:00
|
|
|
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_snow) );
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string DemoSnow::subtitle() const
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ParticleSnow";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoRain
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoRain::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
_emitter = ParticleRain::create();
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->retain();
|
|
|
|
_background->addChild(_emitter, 10);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto p = _emitter->getPosition();
|
2014-05-15 01:07:09 +08:00
|
|
|
_emitter->setPosition( Vec2( p.x, p.y-100) );
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setLife(4);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-11-07 21:48:39 +08:00
|
|
|
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_fire) );
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string DemoRain::subtitle() const
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ParticleRain";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoModernArt
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoModernArt::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-11-30 01:09:38 +08:00
|
|
|
//FIXME: If use ParticleSystemPoint, bada 1.0 device will crash.
|
2013-06-20 14:17:10 +08:00
|
|
|
// Crash place: ParticleSystemPoint.cpp Line 149, function: glDrawArrays(GL_POINTS, 0, _particleIdx);
|
2013-11-15 08:21:49 +08:00
|
|
|
_emitter = ParticleSystemQuad::createWithTotalParticles(1000);
|
|
|
|
_emitter->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_background->addChild(_emitter, 10);
|
|
|
|
////_emitter->release();
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// duration
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setDuration(-1);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// gravity
|
2019-09-24 11:31:35 +08:00
|
|
|
_emitter->setGravity(Vec2(0.0f,0.0f));
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// angle
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setAngle(0);
|
|
|
|
_emitter->setAngleVar(360);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// radial
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setRadialAccel(70);
|
|
|
|
_emitter->setRadialAccelVar(10);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2017-02-10 10:35:52 +08:00
|
|
|
// tangential
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setTangentialAccel(80);
|
|
|
|
_emitter->setTangentialAccelVar(0);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// speed of particles
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setSpeed(50);
|
|
|
|
_emitter->setSpeedVar(10);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// emitter position
|
2014-05-15 01:07:09 +08:00
|
|
|
_emitter->setPosition( Vec2( s.width/2, s.height/2) );
|
|
|
|
_emitter->setPosVar(Vec2::ZERO);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// life of particles
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setLife(2.0f);
|
|
|
|
_emitter->setLifeVar(0.3f);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// emits per frame
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setEmissionRate(_emitter->getTotalParticles()/_emitter->getLife());
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// color of particles
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F startColor(0.5f, 0.5f, 0.5f, 1.0f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartColor(startColor);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F startColorVar(0.5f, 0.5f, 0.5f, 1.0f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartColorVar(startColorVar);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F endColor(0.1f, 0.1f, 0.1f, 0.2f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setEndColor(endColor);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
|
|
|
Color4F endColorVar(0.1f, 0.1f, 0.1f, 0.2f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setEndColorVar(endColorVar);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// size, in pixels
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartSize(1.0f);
|
|
|
|
_emitter->setStartSizeVar(1.0f);
|
|
|
|
_emitter->setEndSize(32.0f);
|
|
|
|
_emitter->setEndSizeVar(8.0f);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// texture
|
2013-11-07 21:48:39 +08:00
|
|
|
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_fire) );
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// additive
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setBlendAdditive(false);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string DemoModernArt::subtitle() const
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Varying size";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
2013-11-30 01:09:38 +08:00
|
|
|
// DemoRing
|
2010-08-23 16:38:10 +08:00
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoRing::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
_emitter = ParticleFlower::create();
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->retain();
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_background->addChild(_emitter, 10);
|
2010-08-23 16:38:10 +08:00
|
|
|
|
2013-11-07 21:48:39 +08:00
|
|
|
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_stars1) );
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setLifeVar(0);
|
|
|
|
_emitter->setLife(10);
|
|
|
|
_emitter->setSpeed(100);
|
|
|
|
_emitter->setSpeedVar(0);
|
|
|
|
_emitter->setEmissionRate(10000);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
setEmitterPosition();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string DemoRing::subtitle() const
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Ring Demo";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ParallaxParticle
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ParallaxParticle::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_background->getParent()->removeChild(_background, true);
|
2014-07-10 00:45:27 +08:00
|
|
|
_background = nullptr;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-11-30 01:09:38 +08:00
|
|
|
auto p = ParallaxNode::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(p, 5);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto p1 = Sprite::create(s_back3);
|
|
|
|
auto p2 = Sprite::create(s_back3);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2019-09-24 11:31:35 +08:00
|
|
|
p->addChild( p1, 1, Vec2(0.5f,1.0f), Vec2(0.0f,250.0f) );
|
|
|
|
p->addChild(p2, 2, Vec2(1.5f,1.0f), Vec2(0.0f,50.0f) );
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
_emitter = ParticleFlower::create();
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->retain();
|
2013-11-07 21:48:39 +08:00
|
|
|
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_fire) );
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
p1->addChild(_emitter, 10);
|
2014-05-15 01:07:09 +08:00
|
|
|
_emitter->setPosition( Vec2(250,200) );
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto par = ParticleSun::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
p2->addChild(par, 10);
|
2013-11-07 21:48:39 +08:00
|
|
|
par->setTexture( Director::getInstance()->getTextureCache()->addImage(s_fire) );
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2019-09-24 11:31:35 +08:00
|
|
|
auto move = MoveBy::create(4, Vec2(300.0f,0.0f));
|
2013-08-16 16:05:27 +08:00
|
|
|
auto move_back = move->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq = Sequence::create( move, move_back, nullptr);
|
2013-11-30 01:09:38 +08:00
|
|
|
p->runAction(RepeatForever::create(seq));
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string ParallaxParticle::subtitle() const
|
2010-09-25 11:54:33 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Parallax + Particles";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2010-09-25 11:54:33 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// RadiusMode1
|
|
|
|
//
|
2012-04-04 21:58:04 +08:00
|
|
|
//------------------------------------------------------------------
|
2010-09-25 11:54:33 +08:00
|
|
|
void RadiusMode1::onEnter()
|
|
|
|
{
|
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-07-08 18:11:32 +08:00
|
|
|
_color->setColor(Color3B::BLACK);
|
2013-06-15 14:03:30 +08:00
|
|
|
removeChild(_background, true);
|
2014-07-10 00:45:27 +08:00
|
|
|
_background = nullptr;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-11-15 08:21:49 +08:00
|
|
|
_emitter = ParticleSystemQuad::createWithTotalParticles(200);
|
|
|
|
_emitter->retain();
|
2013-06-15 14:03:30 +08:00
|
|
|
addChild(_emitter, 10);
|
2013-11-07 21:48:39 +08:00
|
|
|
_emitter->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/stars-grayscale.png"));
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// duration
|
2013-07-25 14:27:46 +08:00
|
|
|
_emitter->setDuration(ParticleSystem::DURATION_INFINITY);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// radius mode
|
2013-07-26 13:47:30 +08:00
|
|
|
_emitter->setEmitterMode(ParticleSystem::Mode::RADIUS);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// radius mode: start and end radius in pixels
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartRadius(0);
|
|
|
|
_emitter->setStartRadiusVar(0);
|
|
|
|
_emitter->setEndRadius(160);
|
|
|
|
_emitter->setEndRadiusVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// radius mode: degrees per second
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setRotatePerSecond(180);
|
|
|
|
_emitter->setRotatePerSecondVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
// angle
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setAngle(90);
|
|
|
|
_emitter->setAngleVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// emitter position
|
2013-08-16 16:05:27 +08:00
|
|
|
auto size = Director::getInstance()->getWinSize();
|
2014-05-15 01:07:09 +08:00
|
|
|
_emitter->setPosition(Vec2(size.width/2, size.height/2));
|
|
|
|
_emitter->setPosVar(Vec2::ZERO);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// life of particles
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setLife(5);
|
|
|
|
_emitter->setLifeVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// spin of particles
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartSpin(0);
|
|
|
|
_emitter->setStartSpinVar(0);
|
|
|
|
_emitter->setEndSpin(0);
|
|
|
|
_emitter->setEndSpinVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// color of particles
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F startColor(0.5f, 0.5f, 0.5f, 1.0f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartColor(startColor);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F startColorVar(0.5f, 0.5f, 0.5f, 1.0f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartColorVar(startColorVar);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F endColor(0.1f, 0.1f, 0.1f, 0.2f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setEndColor(endColor);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-11-30 01:09:38 +08:00
|
|
|
Color4F endColorVar(0.1f, 0.1f, 0.1f, 0.2f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setEndColorVar(endColorVar);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// size, in pixels
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartSize(32);
|
|
|
|
_emitter->setStartSizeVar(0);
|
2013-07-25 14:27:46 +08:00
|
|
|
_emitter->setEndSize(ParticleSystem::START_SIZE_EQUAL_TO_END_SIZE);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// emits per second
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setEmissionRate(_emitter->getTotalParticles() / _emitter->getLife());
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2010-09-25 11:54:33 +08:00
|
|
|
// additive
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setBlendAdditive(false);
|
2010-09-25 11:54:33 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string RadiusMode1::subtitle() const
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
|
|
|
return "Radius Mode: Spiral";
|
|
|
|
}
|
|
|
|
|
2010-09-25 11:54:33 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// RadiusMode2
|
|
|
|
//
|
2012-04-04 21:58:04 +08:00
|
|
|
//------------------------------------------------------------------
|
2010-09-25 11:54:33 +08:00
|
|
|
void RadiusMode2::onEnter()
|
|
|
|
{
|
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-07-08 18:11:32 +08:00
|
|
|
_color->setColor(Color3B::BLACK);
|
2013-06-15 14:03:30 +08:00
|
|
|
removeChild(_background, true);
|
2014-07-10 00:45:27 +08:00
|
|
|
_background = nullptr;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-11-15 08:21:49 +08:00
|
|
|
_emitter = ParticleSystemQuad::createWithTotalParticles(200);
|
|
|
|
_emitter->retain();
|
2013-06-15 14:03:30 +08:00
|
|
|
addChild(_emitter, 10);
|
2013-11-07 21:48:39 +08:00
|
|
|
_emitter->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/stars-grayscale.png"));
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// duration
|
2013-07-25 14:27:46 +08:00
|
|
|
_emitter->setDuration(ParticleSystem::DURATION_INFINITY);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// radius mode
|
2013-07-26 13:47:30 +08:00
|
|
|
_emitter->setEmitterMode(ParticleSystem::Mode::RADIUS);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// radius mode: start and end radius in pixels
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartRadius(100);
|
|
|
|
_emitter->setStartRadiusVar(0);
|
2013-07-25 14:27:46 +08:00
|
|
|
_emitter->setEndRadius(ParticleSystem::START_RADIUS_EQUAL_TO_END_RADIUS);
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setEndRadiusVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// radius mode: degrees per second
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setRotatePerSecond(45);
|
|
|
|
_emitter->setRotatePerSecondVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
// angle
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setAngle(90);
|
|
|
|
_emitter->setAngleVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// emitter position
|
2013-08-16 16:05:27 +08:00
|
|
|
auto size = Director::getInstance()->getWinSize();
|
2014-05-15 01:07:09 +08:00
|
|
|
_emitter->setPosition(Vec2(size.width/2, size.height/2));
|
|
|
|
_emitter->setPosVar(Vec2::ZERO);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// life of particles
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setLife(4);
|
|
|
|
_emitter->setLifeVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// spin of particles
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartSpin(0);
|
|
|
|
_emitter->setStartSpinVar(0);
|
|
|
|
_emitter->setEndSpin(0);
|
|
|
|
_emitter->setEndSpinVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// color of particles
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F startColor(0.5f, 0.5f, 0.5f, 1.0f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartColor(startColor);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F startColorVar(0.5f, 0.5f, 0.5f, 1.0f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartColorVar(startColorVar);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F endColor(0.1f, 0.1f, 0.1f, 0.2f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setEndColor(endColor);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-11-30 01:09:38 +08:00
|
|
|
Color4F endColorVar(0.1f, 0.1f, 0.1f, 0.2f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setEndColorVar(endColorVar);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// size, in pixels
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartSize(32);
|
|
|
|
_emitter->setStartSizeVar(0);
|
2013-07-25 14:27:46 +08:00
|
|
|
_emitter->setEndSize(ParticleSystem::START_SIZE_EQUAL_TO_END_SIZE);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// emits per second
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setEmissionRate(_emitter->getTotalParticles() / _emitter->getLife());
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2010-09-25 11:54:33 +08:00
|
|
|
// additive
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setBlendAdditive(false);
|
2010-09-25 11:54:33 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string RadiusMode2::subtitle() const
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
|
|
|
return "Radius Mode: Semi Circle";
|
|
|
|
}
|
|
|
|
|
2010-09-25 11:54:33 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Issue704
|
|
|
|
//
|
2012-04-04 21:58:04 +08:00
|
|
|
//------------------------------------------------------------------
|
2010-09-25 11:54:33 +08:00
|
|
|
void Issue704::onEnter()
|
|
|
|
{
|
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-07-08 18:11:32 +08:00
|
|
|
_color->setColor(Color3B::BLACK);
|
2013-06-15 14:03:30 +08:00
|
|
|
removeChild(_background, true);
|
2014-07-10 00:45:27 +08:00
|
|
|
_background = nullptr;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-11-15 08:21:49 +08:00
|
|
|
_emitter = ParticleSystemQuad::createWithTotalParticles(100);
|
|
|
|
_emitter->retain();
|
2013-06-15 14:03:30 +08:00
|
|
|
addChild(_emitter, 10);
|
2013-11-07 21:48:39 +08:00
|
|
|
_emitter->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png"));
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// duration
|
2013-07-25 14:27:46 +08:00
|
|
|
_emitter->setDuration(ParticleSystem::DURATION_INFINITY);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// radius mode
|
2013-07-26 13:47:30 +08:00
|
|
|
_emitter->setEmitterMode(ParticleSystem::Mode::RADIUS);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// radius mode: start and end radius in pixels
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartRadius(50);
|
|
|
|
_emitter->setStartRadiusVar(0);
|
2013-07-25 14:27:46 +08:00
|
|
|
_emitter->setEndRadius(ParticleSystem::START_RADIUS_EQUAL_TO_END_RADIUS);
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setEndRadiusVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// radius mode: degrees per second
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setRotatePerSecond(0);
|
|
|
|
_emitter->setRotatePerSecondVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
// angle
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setAngle(90);
|
|
|
|
_emitter->setAngleVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// emitter position
|
2013-08-16 16:05:27 +08:00
|
|
|
auto size = Director::getInstance()->getWinSize();
|
2014-05-15 01:07:09 +08:00
|
|
|
_emitter->setPosition(Vec2(size.width/2, size.height/2));
|
|
|
|
_emitter->setPosVar(Vec2::ZERO);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// life of particles
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setLife(5);
|
|
|
|
_emitter->setLifeVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// spin of particles
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartSpin(0);
|
|
|
|
_emitter->setStartSpinVar(0);
|
|
|
|
_emitter->setEndSpin(0);
|
|
|
|
_emitter->setEndSpinVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// color of particles
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F startColor(0.5f, 0.5f, 0.5f, 1.0f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartColor(startColor);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F startColorVar(0.5f, 0.5f, 0.5f, 1.0f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartColorVar(startColorVar);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F endColor(0.1f, 0.1f, 0.1f, 0.2f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setEndColor(endColor);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-11-30 01:09:38 +08:00
|
|
|
Color4F endColorVar(0.1f, 0.1f, 0.1f, 0.2f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setEndColorVar(endColorVar);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// size, in pixels
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setStartSize(16);
|
|
|
|
_emitter->setStartSizeVar(0);
|
2013-07-25 14:27:46 +08:00
|
|
|
_emitter->setEndSize(ParticleSystem::START_SIZE_EQUAL_TO_END_SIZE);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
// emits per second
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setEmissionRate(_emitter->getTotalParticles() / _emitter->getLife());
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2010-09-25 11:54:33 +08:00
|
|
|
// additive
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->setBlendAdditive(false);
|
2010-09-25 11:54:33 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto rot = RotateBy::create(16, 360);
|
2013-06-20 14:17:10 +08:00
|
|
|
_emitter->runAction(RepeatForever::create(rot));
|
2010-09-25 11:54:33 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string Issue704::title() const
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
|
|
|
return "Issue 704. Free + Rot";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string Issue704::subtitle() const
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
|
|
|
return "Emitted particles should not rotate";
|
|
|
|
}
|
|
|
|
|
2010-09-25 11:54:33 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Issue870
|
|
|
|
//
|
2012-04-04 21:58:04 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
void Issue870::onEnter()
|
|
|
|
{
|
|
|
|
ParticleDemo::onEnter();
|
|
|
|
|
2013-07-08 18:11:32 +08:00
|
|
|
_color->setColor(Color3B::BLACK);
|
2013-06-15 14:03:30 +08:00
|
|
|
removeChild(_background, true);
|
2014-07-10 00:45:27 +08:00
|
|
|
_background = nullptr;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-11-15 08:21:49 +08:00
|
|
|
_emitter = ParticleSystemQuad::create("Particles/SpinningPeas.plist");
|
|
|
|
_emitter->setTextureWithRect(Director::getInstance()->getTextureCache()->addImage("Images/particles.png"), Rect(0,0,32,32));
|
|
|
|
addChild(_emitter, 10);
|
|
|
|
_emitter->retain();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_index = 0;
|
2014-10-04 00:38:36 +08:00
|
|
|
schedule(CC_SCHEDULE_SELECTOR(Issue870::updateQuads), 2.0f);
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void Issue870::updateQuads(float dt)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_index = (_index + 1) % 4;
|
2013-08-16 16:05:27 +08:00
|
|
|
auto rect = Rect(_index * 32, 0, 32, 32);
|
|
|
|
auto system = (ParticleSystemQuad*)_emitter;
|
2013-06-15 14:03:30 +08:00
|
|
|
system->setTextureWithRect(_emitter->getTexture(), rect);
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string Issue870::title() const
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
|
|
|
return "Issue 870. SubRect";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string Issue870::subtitle() const
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
|
|
|
return "Every 2 seconds the particle should change";
|
|
|
|
}
|
|
|
|
|
2010-09-25 11:54:33 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DemoParticleFromFile
|
|
|
|
//
|
2012-04-04 21:58:04 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
void DemoParticleFromFile::onEnter()
|
|
|
|
{
|
|
|
|
ParticleDemo::onEnter();
|
|
|
|
|
2013-07-08 18:11:32 +08:00
|
|
|
_color->setColor(Color3B::BLACK);
|
2013-06-15 14:03:30 +08:00
|
|
|
removeChild(_background, true);
|
2014-07-10 00:45:27 +08:00
|
|
|
_background = nullptr;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
std::string filename = "Particles/" + _title + ".plist";
|
2013-11-15 08:21:49 +08:00
|
|
|
_emitter = ParticleSystemQuad::create(filename);
|
|
|
|
_emitter->retain();
|
2013-06-15 14:03:30 +08:00
|
|
|
addChild(_emitter, 10);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
setEmitterPosition();
|
|
|
|
}
|
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ParticleDemo
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2010-08-23 16:38:10 +08:00
|
|
|
enum
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
IDC_NEXT = 100,
|
|
|
|
IDC_BACK,
|
|
|
|
IDC_RESTART,
|
|
|
|
IDC_TOGGLE
|
2010-08-23 16:38:10 +08:00
|
|
|
};
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
ParticleTests::ParticleTests()
|
|
|
|
{
|
|
|
|
ADD_TEST_CASE(ParticleReorder);
|
|
|
|
ADD_TEST_CASE(ParticleBatchHybrid);
|
|
|
|
ADD_TEST_CASE(ParticleBatchMultipleEmitters);
|
|
|
|
ADD_TEST_CASE(DemoFlower);
|
|
|
|
ADD_TEST_CASE(DemoGalaxy);
|
|
|
|
ADD_TEST_CASE(DemoFirework);
|
|
|
|
ADD_TEST_CASE(DemoSpiral);
|
|
|
|
ADD_TEST_CASE(DemoSun);
|
|
|
|
ADD_TEST_CASE(DemoMeteor);
|
|
|
|
ADD_TEST_CASE(DemoFire);
|
|
|
|
ADD_TEST_CASE(DemoSmoke);
|
|
|
|
ADD_TEST_CASE(DemoExplosion);
|
|
|
|
ADD_TEST_CASE(DemoSnow);
|
|
|
|
ADD_TEST_CASE(DemoRain);
|
|
|
|
ADD_TEST_CASE(DemoBigFlower);
|
|
|
|
ADD_TEST_CASE(DemoRotFlower);
|
|
|
|
ADD_TEST_CASE(DemoModernArt);
|
|
|
|
ADD_TEST_CASE(DemoRing);
|
|
|
|
ADD_TEST_CASE(ParallaxParticle);
|
2016-06-15 18:31:10 +08:00
|
|
|
ADD_TEST_CASE(DemoPause);
|
2015-04-03 14:31:03 +08:00
|
|
|
addTestCase("BoilingFoam", [](){return DemoParticleFromFile::create("BoilingFoam");});
|
|
|
|
addTestCase("BurstPipe", [](){return DemoParticleFromFile::create("BurstPipe"); });
|
|
|
|
addTestCase("Comet", [](){return DemoParticleFromFile::create("Comet"); });
|
|
|
|
addTestCase("debian", [](){return DemoParticleFromFile::create("debian"); });
|
|
|
|
addTestCase("ExplodingRing", [](){return DemoParticleFromFile::create("ExplodingRing"); });
|
|
|
|
addTestCase("LavaFlow", [](){return DemoParticleFromFile::create("LavaFlow"); });
|
|
|
|
addTestCase("SpinningPeas", [](){return DemoParticleFromFile::create("SpinningPeas"); });
|
|
|
|
addTestCase("SpookyPeas", [](){return DemoParticleFromFile::create("SpookyPeas"); });
|
|
|
|
addTestCase("Upsidedown", [](){return DemoParticleFromFile::create("Upsidedown"); });
|
|
|
|
addTestCase("Flower", [](){return DemoParticleFromFile::create("Flower"); });
|
|
|
|
addTestCase("Spiral", [](){return DemoParticleFromFile::create("Spiral"); });
|
|
|
|
addTestCase("Galaxy", [](){return DemoParticleFromFile::create("Galaxy"); });
|
|
|
|
addTestCase("Phoenix", [](){return DemoParticleFromFile::create("Phoenix"); });
|
|
|
|
addTestCase("lines", [](){return DemoParticleFromFile::create("lines"); });
|
|
|
|
addTestCase("ButterFly", [](){return DemoParticleFromFile::create("ButterFly"); });
|
|
|
|
addTestCase("ButterFlyYFlipped", [](){return DemoParticleFromFile::create("ButterFlyYFlipped"); });
|
|
|
|
ADD_TEST_CASE(RadiusMode1);
|
|
|
|
ADD_TEST_CASE(RadiusMode2);
|
|
|
|
ADD_TEST_CASE(Issue704);
|
|
|
|
ADD_TEST_CASE(Issue870);
|
|
|
|
ADD_TEST_CASE(Issue1201);
|
|
|
|
|
|
|
|
ADD_TEST_CASE(MultipleParticleSystems);
|
|
|
|
ADD_TEST_CASE(MultipleParticleSystemsBatched);
|
|
|
|
ADD_TEST_CASE(AddAndDeleteParticleSystems);
|
|
|
|
ADD_TEST_CASE(ReorderParticleSystems);
|
|
|
|
ADD_TEST_CASE(PremultipliedAlphaTest);
|
|
|
|
ADD_TEST_CASE(PremultipliedAlphaTest2);
|
|
|
|
ADD_TEST_CASE(Issue3990);
|
|
|
|
ADD_TEST_CASE(ParticleAutoBatching);
|
|
|
|
ADD_TEST_CASE(ParticleVisibleTest);
|
|
|
|
ADD_TEST_CASE(ParticleResetTotalParticles);
|
2015-06-12 15:39:57 +08:00
|
|
|
|
|
|
|
ADD_TEST_CASE(ParticleIssue12310);
|
2017-01-12 11:48:30 +08:00
|
|
|
ADD_TEST_CASE(ParticleSpriteFrame);
|
2013-11-30 01:09:38 +08:00
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2019-07-22 09:38:46 +08:00
|
|
|
ParticleDemo::~ParticleDemo()
|
2012-04-24 15:02:18 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RELEASE(_emitter);
|
2012-04-24 15:02:18 +08:00
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2019-07-22 09:38:46 +08:00
|
|
|
void ParticleDemo::onEnter()
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2015-04-03 14:31:03 +08:00
|
|
|
TestCase::onEnter();
|
2013-06-07 08:12:28 +08:00
|
|
|
|
2017-04-27 09:25:20 +08:00
|
|
|
MenuItemFont::setFontSize(32);
|
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
_color = LayerColor::create( Color4B(127,127,127,255) );
|
2013-06-15 14:03:30 +08:00
|
|
|
this->addChild(_color);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
_emitter = nullptr;
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-10-23 16:14:03 +08:00
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
|
|
|
listener->onTouchesBegan = CC_CALLBACK_2(ParticleDemo::onTouchesBegan, this);
|
|
|
|
listener->onTouchesMoved = CC_CALLBACK_2(ParticleDemo::onTouchesMoved, this);
|
|
|
|
listener->onTouchesEnded = CC_CALLBACK_2(ParticleDemo::onTouchesEnded, this);
|
2013-10-26 15:04:01 +08:00
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto item4 = MenuItemToggle::createWithCallback( CC_CALLBACK_1(ParticleDemo::toggleCallback, this),
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::create( "Free Movement" ),
|
|
|
|
MenuItemFont::create( "Relative Movement" ),
|
|
|
|
MenuItemFont::create( "Grouped Movement" ),
|
2014-07-10 00:45:27 +08:00
|
|
|
nullptr );
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto menu = Menu::create(item4, nullptr);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
menu->setPosition( Vec2::ZERO );
|
|
|
|
item4->setPosition( Vec2( VisibleRect::left().x, VisibleRect::bottom().y+ 100) );
|
|
|
|
item4->setAnchorPoint( Vec2(0,0) );
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild( menu, 100 );
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto labelAtlas = LabelAtlas::create("0000", "fps_images.png", 12, 32, '.');
|
2012-04-04 21:58:04 +08:00
|
|
|
addChild(labelAtlas, 100, kTagParticleCount);
|
2019-09-24 11:31:35 +08:00
|
|
|
labelAtlas->setPosition(Vec2(s.width-66,50.0f));
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2012-04-04 21:58:04 +08:00
|
|
|
// moving background
|
2013-06-20 14:17:10 +08:00
|
|
|
_background = Sprite::create(s_back3);
|
2013-06-15 14:03:30 +08:00
|
|
|
addChild(_background, 5);
|
2014-05-15 01:07:09 +08:00
|
|
|
_background->setPosition( Vec2(s.width/2, s.height-180) );
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
auto move = MoveBy::create(4, Vec2(300,0) );
|
2013-08-16 16:05:27 +08:00
|
|
|
auto move_back = move->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq = Sequence::create( move, move_back, nullptr);
|
2013-06-20 14:17:10 +08:00
|
|
|
_background->runAction( RepeatForever::create(seq) );
|
2013-11-30 01:09:38 +08:00
|
|
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
scheduleUpdate();
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ParticleDemo::title() const
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2014-02-28 23:02:22 +08:00
|
|
|
return "Particle Demo";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ParticleDemo::subtitle() const
|
2012-04-24 15:02:18 +08:00
|
|
|
{
|
2013-11-30 01:09:38 +08:00
|
|
|
return "No title";
|
2012-04-24 15:02:18 +08:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void ParticleDemo::onTouchesBegan(const std::vector<Touch*>& touches, Event *event)
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2013-09-03 18:22:03 +08:00
|
|
|
onTouchesEnded(touches, event);
|
2010-08-23 16:38:10 +08:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void ParticleDemo::onTouchesMoved(const std::vector<Touch*>& touches, Event *event)
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2013-09-03 18:22:03 +08:00
|
|
|
return onTouchesEnded(touches, event);
|
2010-08-23 16:38:10 +08:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void ParticleDemo::onTouchesEnded(const std::vector<Touch*>& touches, Event *event)
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2013-09-03 18:22:03 +08:00
|
|
|
auto touch = touches[0];
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto location = touch->getLocation();
|
2010-09-25 11:54:33 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
auto pos = Vec2::ZERO;
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_background)
|
2010-09-25 11:54:33 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
pos = _background->convertToWorldSpace(Vec2::ZERO);
|
2010-09-25 11:54:33 +08:00
|
|
|
}
|
2012-03-22 18:29:07 +08:00
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
if (_emitter != nullptr)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-12 18:04:32 +08:00
|
|
|
_emitter->setPosition(location -pos);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2010-08-23 16:38:10 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void ParticleDemo::update(float dt)
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_emitter)
|
2010-08-25 13:45:28 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto atlas = (LabelAtlas*)getChildByTag(kTagParticleCount);
|
2012-04-04 21:58:04 +08:00
|
|
|
char str[5] = {0};
|
2013-06-15 14:03:30 +08:00
|
|
|
sprintf(str, "%04d", _emitter->getParticleCount());
|
2012-04-04 21:58:04 +08:00
|
|
|
atlas->setString(str);
|
|
|
|
}
|
2010-08-23 16:38:10 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void ParticleDemo::toggleCallback(Ref* sender)
|
2010-08-23 16:38:10 +08:00
|
|
|
{
|
2014-07-10 00:45:27 +08:00
|
|
|
if (_emitter != nullptr)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-26 13:47:30 +08:00
|
|
|
if (_emitter->getPositionType() == ParticleSystem::PositionType::GROUPED)
|
|
|
|
_emitter->setPositionType(ParticleSystem::PositionType::FREE);
|
|
|
|
else if (_emitter->getPositionType() == ParticleSystem::PositionType::FREE)
|
|
|
|
_emitter->setPositionType(ParticleSystem::PositionType::RELATIVE);
|
|
|
|
else if (_emitter->getPositionType() == ParticleSystem::PositionType::RELATIVE)
|
|
|
|
_emitter->setPositionType(ParticleSystem::PositionType::GROUPED );
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2010-08-23 16:38:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ParticleDemo::setEmitterPosition()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2014-07-10 00:45:27 +08:00
|
|
|
if (_emitter != nullptr)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
_emitter->setPosition( Vec2(s.width / 2, s.height / 2) );
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ParticleBatchHybrid
|
|
|
|
|
|
|
|
void ParticleBatchHybrid::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-07-08 18:11:32 +08:00
|
|
|
_color->setColor(Color3B::BLACK);
|
2013-06-15 14:03:30 +08:00
|
|
|
removeChild(_background, true);
|
2014-07-10 00:45:27 +08:00
|
|
|
_background = nullptr;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
_emitter = ParticleSystemQuad::create("Particles/LavaFlow.plist");
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->retain();
|
2013-08-16 16:05:27 +08:00
|
|
|
auto batch = ParticleBatchNode::createWithTexture(_emitter->getTexture());
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
batch->addChild(_emitter);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(batch, 10);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2014-10-04 00:38:36 +08:00
|
|
|
schedule(CC_SCHEDULE_SELECTOR(ParticleBatchHybrid::switchRender), 2.0f);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto node = Node::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(node);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_parent1 = batch;
|
|
|
|
_parent2 = node;
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void ParticleBatchHybrid::switchRender(float dt)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2014-07-10 00:45:27 +08:00
|
|
|
bool usingBatch = ( _emitter->getBatchNode() != nullptr );
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->removeFromParentAndCleanup(false);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto newParent = (usingBatch ? _parent2 : _parent1 );
|
2013-06-15 14:03:30 +08:00
|
|
|
newParent->addChild(_emitter);
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Particle: Using new parent: %s", usingBatch ? "CCNode" : "CCParticleBatchNode");
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ParticleBatchHybrid::title() const
|
2012-03-22 18:29:07 +08:00
|
|
|
{
|
2013-11-30 01:09:38 +08:00
|
|
|
return "Particle Batch";
|
2012-03-22 18:29:07 +08:00
|
|
|
}
|
2010-08-26 09:55:54 +08:00
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ParticleBatchHybrid::subtitle() const
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Hybrid: batched and non batched every 2 seconds";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ParticleBatchMultipleEmitters
|
|
|
|
|
|
|
|
void ParticleBatchMultipleEmitters::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-07-08 18:11:32 +08:00
|
|
|
_color->setColor(Color3B::BLACK);
|
2013-06-15 14:03:30 +08:00
|
|
|
removeChild(_background, true);
|
2014-07-10 00:45:27 +08:00
|
|
|
_background = nullptr;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto emitter1 = ParticleSystemQuad::create("Particles/LavaFlow.plist");
|
2013-07-05 16:49:22 +08:00
|
|
|
emitter1->setStartColor(Color4F(1,0,0,1));
|
2013-08-16 16:05:27 +08:00
|
|
|
auto emitter2 = ParticleSystemQuad::create("Particles/LavaFlow.plist");
|
2013-07-05 16:49:22 +08:00
|
|
|
emitter2->setStartColor(Color4F(0,1,0,1));
|
2013-08-16 16:05:27 +08:00
|
|
|
auto emitter3 = ParticleSystemQuad::create("Particles/LavaFlow.plist");
|
2013-07-05 16:49:22 +08:00
|
|
|
emitter3->setStartColor(Color4F(0,0,1,1));
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
emitter1->setPosition(Vec2( s.width/1.25f, s.height/1.25f));
|
|
|
|
emitter2->setPosition(Vec2( s.width/2, s.height/2));
|
|
|
|
emitter3->setPosition(Vec2( s.width/4, s.height/4));
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto batch = ParticleBatchNode::createWithTexture(emitter1->getTexture());
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
batch->addChild(emitter1, 0);
|
|
|
|
batch->addChild(emitter2, 0);
|
|
|
|
batch->addChild(emitter3, 0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(batch, 10);
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ParticleBatchMultipleEmitters::title() const
|
2012-03-22 18:29:07 +08:00
|
|
|
{
|
2013-11-30 01:09:38 +08:00
|
|
|
return "Particle Batch";
|
2012-03-22 18:29:07 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ParticleBatchMultipleEmitters::subtitle() const
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Multiple emitters. One Batch";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ParticleReorder
|
|
|
|
|
|
|
|
void ParticleReorder::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_order = 0;
|
2013-07-08 18:11:32 +08:00
|
|
|
_color->setColor(Color3B::BLACK);
|
2013-06-15 14:03:30 +08:00
|
|
|
removeChild(_background, true);
|
2014-07-10 00:45:27 +08:00
|
|
|
_background = nullptr;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto ignore = ParticleSystemQuad::create("Particles/SmallSun.plist");
|
|
|
|
auto parent1 = Node::create();
|
|
|
|
auto parent2 = ParticleBatchNode::createWithTexture(ignore->getTexture());
|
2012-04-04 21:58:04 +08:00
|
|
|
ignore->unscheduleUpdate();
|
|
|
|
|
2013-11-30 01:09:38 +08:00
|
|
|
for( unsigned int i=0; i<2;i++)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto parent = ( i==0 ? parent1 : parent2 );
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto emitter1 = ParticleSystemQuad::create("Particles/SmallSun.plist");
|
2013-07-05 16:49:22 +08:00
|
|
|
emitter1->setStartColor(Color4F(1,0,0,1));
|
2012-06-15 15:10:40 +08:00
|
|
|
emitter1->setBlendAdditive(false);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto emitter2 = ParticleSystemQuad::create("Particles/SmallSun.plist");
|
2013-07-05 16:49:22 +08:00
|
|
|
emitter2->setStartColor(Color4F(0,1,0,1));
|
2012-06-15 15:10:40 +08:00
|
|
|
emitter2->setBlendAdditive(false);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto emitter3 = ParticleSystemQuad::create("Particles/SmallSun.plist");
|
2013-07-05 16:49:22 +08:00
|
|
|
emitter3->setStartColor(Color4F(0,0,1,1));
|
2012-06-15 15:10:40 +08:00
|
|
|
emitter3->setBlendAdditive(false);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
int neg = (i==0 ? 1 : -1 );
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
emitter1->setPosition(Vec2( s.width/2-30, s.height/2+60*neg));
|
|
|
|
emitter2->setPosition(Vec2( s.width/2, s.height/2+60*neg));
|
|
|
|
emitter3->setPosition(Vec2( s.width/2+30, s.height/2+60*neg));
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
parent->addChild(emitter1, 0, 1);
|
|
|
|
parent->addChild(emitter2, 0, 2);
|
|
|
|
parent->addChild(emitter3, 0, 3);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(parent, 10, 1000+i);
|
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2014-10-04 00:38:36 +08:00
|
|
|
schedule(CC_SCHEDULE_SELECTOR(ParticleReorder::reorderParticles), 1.0f);
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ParticleReorder::title() const
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Reordering particles";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ParticleReorder::subtitle() const
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Reordering particles with and without batches batches";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void ParticleReorder::reorderParticles(float dt)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
for( int i=0; i<2;i++) {
|
2013-08-16 16:05:27 +08:00
|
|
|
auto parent = getChildByTag(1000+i);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto child1 = parent->getChildByTag(1);
|
|
|
|
auto child2 = parent->getChildByTag(2);
|
|
|
|
auto child3 = parent->getChildByTag(3);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if( _order % 3 == 0 ) {
|
2012-04-19 14:35:52 +08:00
|
|
|
parent->reorderChild(child1, 1);
|
|
|
|
parent->reorderChild(child2, 2);
|
|
|
|
parent->reorderChild(child3, 3);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
} else if (_order % 3 == 1 ) {
|
2012-04-19 14:35:52 +08:00
|
|
|
parent->reorderChild(child1, 3);
|
|
|
|
parent->reorderChild(child2, 1);
|
|
|
|
parent->reorderChild(child3, 2);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
} else if (_order % 3 == 2 ) {
|
2012-04-19 14:35:52 +08:00
|
|
|
parent->reorderChild(child1, 2);
|
|
|
|
parent->reorderChild(child2, 3);
|
|
|
|
parent->reorderChild(child3, 1);
|
|
|
|
}
|
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_order++;
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
class RainbowEffect : public ParticleSystemQuad
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-07-15 12:04:48 +08:00
|
|
|
bool init()override;
|
2013-11-16 05:14:12 +08:00
|
|
|
virtual bool initWithTotalParticles(int numberOfParticles) override;
|
|
|
|
virtual void update(float dt) override;
|
2012-04-04 21:58:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
bool RainbowEffect::init()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return initWithTotalParticles(150);
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2013-11-16 05:14:12 +08:00
|
|
|
bool RainbowEffect::initWithTotalParticles(int numberOfParticles)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
// additive
|
2012-06-15 15:10:40 +08:00
|
|
|
setBlendAdditive(false);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// duration
|
2013-07-25 14:27:46 +08:00
|
|
|
setDuration(ParticleSystem::DURATION_INFINITY);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// Gravity Mode
|
2013-07-26 13:47:30 +08:00
|
|
|
setEmitterMode(ParticleSystem::Mode::GRAVITY);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// Gravity Mode: gravity
|
2019-09-24 11:31:35 +08:00
|
|
|
setGravity(Vec2(0.0f,0.0f));
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// Gravity mode: radial acceleration
|
|
|
|
setRadialAccel(0);
|
|
|
|
setRadialAccelVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// Gravity mode: speed of particles
|
|
|
|
setSpeed(120);
|
|
|
|
setSpeedVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// angle
|
|
|
|
setAngle(180);
|
|
|
|
setAngleVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// emitter position
|
2013-08-16 16:05:27 +08:00
|
|
|
auto winSize = Director::getInstance()->getWinSize();
|
2014-05-15 01:07:09 +08:00
|
|
|
setPosition(Vec2(winSize.width/2, winSize.height/2));
|
|
|
|
setPosVar(Vec2::ZERO);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// life of particles
|
|
|
|
setLife(0.5f);
|
|
|
|
setLifeVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// size, in pixels
|
|
|
|
setStartSize(25.0f);
|
|
|
|
setStartSizeVar(0);
|
2013-07-25 14:27:46 +08:00
|
|
|
setEndSize(ParticleSystem::START_SIZE_EQUAL_TO_END_SIZE);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// emits per seconds
|
|
|
|
setEmissionRate(getTotalParticles()/getLife());
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// color of particles
|
2013-07-05 16:49:22 +08:00
|
|
|
setStartColor(Color4F(Color4B(50, 50, 50, 50)));
|
|
|
|
setEndColor(Color4F(Color4B(0, 0, 0, 0)));
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_startColorVar.r = 0.0f;
|
|
|
|
_startColorVar.g = 0.0f;
|
|
|
|
_startColorVar.b = 0.0f;
|
|
|
|
_startColorVar.a = 0.0f;
|
|
|
|
_endColorVar.r = 0.0f;
|
|
|
|
_endColorVar.g = 0.0f;
|
|
|
|
_endColorVar.b = 0.0f;
|
|
|
|
_endColorVar.a = 0.0f;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-11-07 21:48:39 +08:00
|
|
|
setTexture(Director::getInstance()->getTextureCache()->addImage("Images/particles.png"));
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return false;
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void RainbowEffect::update(float dt)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitCounter = 0;
|
2013-06-20 14:17:10 +08:00
|
|
|
ParticleSystemQuad::update(dt);
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Issue1201::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-07-08 18:11:32 +08:00
|
|
|
_color->setColor(Color3B::BLACK);
|
2013-06-15 14:03:30 +08:00
|
|
|
removeChild(_background, true);
|
2014-07-10 00:45:27 +08:00
|
|
|
_background = nullptr;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2014-08-28 07:31:57 +08:00
|
|
|
RainbowEffect *particle = new (std::nothrow) RainbowEffect();
|
2012-04-19 14:35:52 +08:00
|
|
|
particle->initWithTotalParticles(50);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(particle);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
particle->setPosition(Vec2(s.width/2, s.height/2));
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter = particle;
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string Issue1201::title() const
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Issue 1201. Unfinished";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string Issue1201::subtitle() const
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Unfinished test. Ignore it";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MultipleParticleSystems::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-07-08 18:11:32 +08:00
|
|
|
_color->setColor(Color3B::BLACK);
|
2013-06-15 14:03:30 +08:00
|
|
|
removeChild(_background, true);
|
2014-07-10 00:45:27 +08:00
|
|
|
_background = nullptr;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-11-30 01:09:38 +08:00
|
|
|
Director::getInstance()->getTextureCache()->addImage("Images/particles.png");
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
for (int i = 0; i<5; i++) {
|
2013-08-16 16:05:27 +08:00
|
|
|
auto particleSystem = ParticleSystemQuad::create("Particles/SpinningPeas.plist");
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2019-09-24 11:31:35 +08:00
|
|
|
particleSystem->setPosition(Vec2(i*50.0f,i*50.0f));
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-07-26 13:47:30 +08:00
|
|
|
particleSystem->setPositionType(ParticleSystem::PositionType::GROUPED);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(particleSystem);
|
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
_emitter = nullptr;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string MultipleParticleSystems::title() const
|
2012-03-22 18:29:07 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Multiple particle systems";
|
2012-03-22 18:29:07 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string MultipleParticleSystems::subtitle() const
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "v1.1 test: FPS should be lower than next test";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void MultipleParticleSystems::update(float dt)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto atlas = (LabelAtlas*) getChildByTag(kTagParticleCount);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-11-28 18:23:06 +08:00
|
|
|
unsigned int count = 0;
|
|
|
|
|
2013-12-20 05:34:41 +08:00
|
|
|
for(const auto &child : _children) {
|
2013-11-28 18:23:06 +08:00
|
|
|
auto item = dynamic_cast<ParticleSystem*>(child);
|
2014-07-10 00:45:27 +08:00
|
|
|
if (item != nullptr)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-11-30 01:09:38 +08:00
|
|
|
count += item->getParticleCount();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-12-20 05:34:41 +08:00
|
|
|
}
|
2013-11-28 18:23:06 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
char str[100] = {0};
|
|
|
|
sprintf(str, "%4d", count);
|
|
|
|
atlas->setString(str);
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// MultipleParticleSystemsBatched
|
|
|
|
|
|
|
|
void MultipleParticleSystemsBatched::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-07-08 18:11:32 +08:00
|
|
|
_color->setColor(Color3B::BLACK);
|
2013-06-15 14:03:30 +08:00
|
|
|
removeChild(_background, true);
|
2014-07-10 00:45:27 +08:00
|
|
|
_background = nullptr;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2014-01-03 18:15:56 +08:00
|
|
|
ParticleBatchNode *batchNode = ParticleBatchNode::createWithTexture(nullptr, 3000);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(batchNode, 1, 2);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
for (int i = 0; i<5; i++) {
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto particleSystem = ParticleSystemQuad::create("Particles/SpinningPeas.plist");
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-07-26 13:47:30 +08:00
|
|
|
particleSystem->setPositionType(ParticleSystem::PositionType::GROUPED);
|
2019-09-24 11:31:35 +08:00
|
|
|
particleSystem->setPosition(Vec2(i*50.0f,i*50.0f));
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
batchNode->setTexture(particleSystem->getTexture());
|
|
|
|
batchNode->addChild(particleSystem);
|
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
_emitter = nullptr;
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void MultipleParticleSystemsBatched::update(float dt)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto atlas = (LabelAtlas*) getChildByTag(kTagParticleCount);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-20 05:34:41 +08:00
|
|
|
int count = 0;
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto batchNode = getChildByTag(2);
|
2013-12-20 05:34:41 +08:00
|
|
|
for(const auto &child : batchNode->getChildren()) {
|
2013-11-29 10:37:40 +08:00
|
|
|
auto item = dynamic_cast<ParticleSystem*>(child);
|
2014-07-10 00:45:27 +08:00
|
|
|
if (item != nullptr)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-11-30 01:09:38 +08:00
|
|
|
count += item->getParticleCount();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-12-20 05:34:41 +08:00
|
|
|
}
|
2013-11-29 10:37:40 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
char str[50] = {0};
|
|
|
|
sprintf(str, "%4d", count);
|
|
|
|
atlas->setString(str);
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string MultipleParticleSystemsBatched::title() const
|
2012-03-22 18:29:07 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Multiple particle systems batched";
|
2012-03-22 18:29:07 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string MultipleParticleSystemsBatched::subtitle() const
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "v1.1 test: should perform better than previous test";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddAndDeleteParticleSystems
|
|
|
|
|
|
|
|
void AddAndDeleteParticleSystems::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-07-08 18:11:32 +08:00
|
|
|
_color->setColor(Color3B::BLACK);
|
2013-06-15 14:03:30 +08:00
|
|
|
removeChild(_background, true);
|
2014-07-10 00:45:27 +08:00
|
|
|
_background = nullptr;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
//adds the texture inside the plist to the texture cache
|
2014-07-10 00:45:27 +08:00
|
|
|
_batchNode = ParticleBatchNode::createWithTexture((Texture2D*)nullptr, 16000);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
addChild(_batchNode, 1, 2);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
for (int i = 0; i<6; i++) {
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto particleSystem = ParticleSystemQuad::create("Particles/Spiral.plist");
|
2013-06-15 14:03:30 +08:00
|
|
|
_batchNode->setTexture(particleSystem->getTexture());
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-07-26 13:47:30 +08:00
|
|
|
particleSystem->setPositionType(ParticleSystem::PositionType::GROUPED);
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setTotalParticles(200);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2019-09-24 11:31:35 +08:00
|
|
|
particleSystem->setPosition(Vec2(i*15 +100.0f,i*15+100.0f));
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-11-30 01:09:38 +08:00
|
|
|
unsigned int randZ = rand() % 100;
|
2013-06-15 14:03:30 +08:00
|
|
|
_batchNode->addChild(particleSystem, randZ, -1);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2014-10-04 00:38:36 +08:00
|
|
|
schedule(CC_SCHEDULE_SELECTOR(AddAndDeleteParticleSystems::removeSystem), 0.5f);
|
2014-07-10 00:45:27 +08:00
|
|
|
_emitter = nullptr;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void AddAndDeleteParticleSystems::removeSystem(float dt)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2014-03-20 16:24:55 +08:00
|
|
|
ssize_t nChildrenCount = _batchNode->getChildren().size();
|
2013-11-29 10:37:40 +08:00
|
|
|
if (nChildrenCount > 0)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
CCLOG("remove random system");
|
|
|
|
unsigned int uRand = rand() % (nChildrenCount - 1);
|
2013-12-05 10:35:10 +08:00
|
|
|
_batchNode->removeChild(_batchNode->getChildren().at(uRand), true);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto particleSystem = ParticleSystemQuad::create("Particles/Spiral.plist");
|
2012-04-19 14:35:52 +08:00
|
|
|
//add new
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-07-26 13:47:30 +08:00
|
|
|
particleSystem->setPositionType(ParticleSystem::PositionType::GROUPED);
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setTotalParticles(200);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
particleSystem->setPosition(Vec2(rand() % 300 ,rand() % 400));
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCLOG("add a new system");
|
2013-11-30 01:09:38 +08:00
|
|
|
unsigned int randZ = rand() % 100;
|
2013-06-15 14:03:30 +08:00
|
|
|
_batchNode->addChild(particleSystem, randZ, -1);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void AddAndDeleteParticleSystems::update(float dt)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto atlas = (LabelAtlas*) getChildByTag(kTagParticleCount);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-20 05:34:41 +08:00
|
|
|
int count = 0;
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto batchNode = getChildByTag(2);
|
2013-12-20 05:34:41 +08:00
|
|
|
for(const auto &child : batchNode->getChildren()) {
|
2013-11-29 10:37:40 +08:00
|
|
|
auto item = dynamic_cast<ParticleSystem*>(child);
|
2014-07-10 00:45:27 +08:00
|
|
|
if (item != nullptr)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-11-30 01:09:38 +08:00
|
|
|
count += item->getParticleCount();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-12-20 05:34:41 +08:00
|
|
|
}
|
2013-11-29 10:37:40 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
char str[100] = {0};
|
|
|
|
sprintf(str, "%4d", count);
|
|
|
|
atlas->setString(str);
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string AddAndDeleteParticleSystems::title() const
|
2012-03-22 18:29:07 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Add and remove Particle System";
|
2012-03-22 18:29:07 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string AddAndDeleteParticleSystems::subtitle() const
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "v1.1 test: every 2 sec 1 system disappear, 1 appears";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ReorderParticleSystems
|
|
|
|
|
|
|
|
void ReorderParticleSystems::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ParticleDemo::onEnter();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-07-08 18:11:32 +08:00
|
|
|
_color->setColor(Color3B::BLACK);
|
2013-06-15 14:03:30 +08:00
|
|
|
removeChild(_background ,true);
|
2014-07-10 00:45:27 +08:00
|
|
|
_background = nullptr;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
_batchNode = ParticleBatchNode::create("Images/stars-grayscale.png" ,3000);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
addChild(_batchNode, 1, 2);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
for (int i = 0; i<3; i++) {
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-11-15 08:21:49 +08:00
|
|
|
auto particleSystem = ParticleSystemQuad::createWithTotalParticles(200);
|
|
|
|
particleSystem->retain();
|
2013-06-15 14:03:30 +08:00
|
|
|
particleSystem->setTexture(_batchNode->getTexture());
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// duration
|
2013-07-25 14:27:46 +08:00
|
|
|
particleSystem->setDuration(ParticleSystem::DURATION_INFINITY);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// radius mode
|
2013-07-26 13:47:30 +08:00
|
|
|
particleSystem->setEmitterMode(ParticleSystem::Mode::RADIUS);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// radius mode: 100 pixels from center
|
|
|
|
particleSystem->setStartRadius(100);
|
|
|
|
particleSystem->setStartRadiusVar(0);
|
2013-07-25 14:27:46 +08:00
|
|
|
particleSystem->setEndRadius(ParticleSystem::START_RADIUS_EQUAL_TO_END_RADIUS);
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setEndRadiusVar(0); // not used when start == end
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// radius mode: degrees per second
|
|
|
|
// 45 * 4 seconds of life = 180 degrees
|
|
|
|
particleSystem->setRotatePerSecond(45);
|
|
|
|
particleSystem->setRotatePerSecondVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// angle
|
|
|
|
particleSystem->setAngle(90);
|
|
|
|
particleSystem->setAngleVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// emitter position
|
2014-05-15 01:07:09 +08:00
|
|
|
particleSystem->setPosVar(Vec2::ZERO);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// life of particles
|
|
|
|
particleSystem->setLife(4);
|
|
|
|
particleSystem->setLifeVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// spin of particles
|
|
|
|
particleSystem->setStartSpin(0);
|
|
|
|
particleSystem->setStartSpinVar(0);
|
|
|
|
particleSystem->setEndSpin(0);
|
|
|
|
particleSystem->setEndSpinVar(0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// color of particles
|
|
|
|
float color[3] = {0,0,0};
|
|
|
|
color[i] = 1;
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F startColor(color[0], color[1], color[2], 1.0f);
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setStartColor(startColor);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F startColorVar(0, 0, 0, 0);
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setStartColorVar(startColorVar);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
Color4F endColor = startColor;
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setEndColor(endColor);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
Color4F endColorVar = startColorVar;
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setEndColorVar(endColorVar);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// size, in pixels
|
|
|
|
particleSystem->setStartSize(32);
|
|
|
|
particleSystem->setStartSizeVar(0);
|
2013-07-25 14:27:46 +08:00
|
|
|
particleSystem->setEndSize(ParticleSystem::START_SIZE_EQUAL_TO_END_SIZE);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// emits per second
|
|
|
|
particleSystem->setEmissionRate(particleSystem->getTotalParticles()/particleSystem->getLife());
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// additive
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2019-09-24 11:31:35 +08:00
|
|
|
particleSystem->setPosition(Vec2(i*10+120.0f,200.0f));
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_batchNode->addChild(particleSystem);
|
2013-07-26 13:47:30 +08:00
|
|
|
particleSystem->setPositionType(ParticleSystem::PositionType::FREE);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->release();
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
//[pBNode addChild:particleSystem z:10 tag:0);
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2014-10-04 00:38:36 +08:00
|
|
|
schedule(CC_SCHEDULE_SELECTOR(ReorderParticleSystems::reorderSystem), 2.0f);
|
2014-07-10 00:45:27 +08:00
|
|
|
_emitter = nullptr;
|
2012-04-04 21:58:04 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void ReorderParticleSystems::reorderSystem(float time)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2013-12-05 10:35:10 +08:00
|
|
|
auto system = static_cast<ParticleSystem*>(_batchNode->getChildren().at(1));
|
2014-01-20 15:03:30 +08:00
|
|
|
_batchNode->reorderChild(system, system->getLocalZOrder() - 1);
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void ReorderParticleSystems::update(float dt)
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2013-11-29 10:37:40 +08:00
|
|
|
auto atlas = static_cast<LabelAtlas*>(getChildByTag(kTagParticleCount));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-20 05:34:41 +08:00
|
|
|
int count = 0;
|
2013-11-30 01:09:38 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto batchNode = getChildByTag(2);
|
2013-12-20 05:34:41 +08:00
|
|
|
for(const auto &child : batchNode->getChildren()) {
|
2013-11-29 10:37:40 +08:00
|
|
|
auto item = dynamic_cast<ParticleSystem*>(child);
|
|
|
|
if (item != nullptr)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-11-30 01:09:38 +08:00
|
|
|
count += item->getParticleCount();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-12-20 05:34:41 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
char str[100] = {0};
|
|
|
|
sprintf(str, "%4d", count);
|
|
|
|
atlas->setString(str);
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ReorderParticleSystems::title() const
|
2012-03-22 18:29:07 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "reorder systems";
|
2012-03-22 18:29:07 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ReorderParticleSystems::subtitle() const
|
2012-04-04 21:58:04 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "changes every 2 seconds";
|
2012-04-04 21:58:04 +08:00
|
|
|
}
|
2012-06-15 15:10:40 +08:00
|
|
|
|
|
|
|
// PremultipliedAlphaTest
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string PremultipliedAlphaTest::title() const
|
2012-06-12 15:40:31 +08:00
|
|
|
{
|
2014-03-24 18:20:11 +08:00
|
|
|
return "premultiplied alpha and readd child test";
|
2012-06-12 15:40:31 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string PremultipliedAlphaTest::subtitle() const
|
2012-06-15 15:10:40 +08:00
|
|
|
{
|
2014-03-24 18:20:11 +08:00
|
|
|
return "no black halo, particles should fade out\n animation should be normal";
|
2012-06-15 15:10:40 +08:00
|
|
|
}
|
|
|
|
|
2017-03-23 09:30:42 +08:00
|
|
|
void PremultipliedAlphaTest::readdParticle(float delta)
|
2014-03-24 18:08:55 +08:00
|
|
|
{
|
2014-06-04 10:39:18 +08:00
|
|
|
if (_hasEmitter)
|
2014-03-24 18:08:55 +08:00
|
|
|
{
|
|
|
|
_emitter->removeFromParent();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->addChild(_emitter);
|
|
|
|
}
|
2014-06-04 10:39:18 +08:00
|
|
|
|
|
|
|
_hasEmitter = !_hasEmitter;
|
2014-03-24 18:08:55 +08:00
|
|
|
}
|
|
|
|
|
2012-06-15 15:10:40 +08:00
|
|
|
void PremultipliedAlphaTest::onEnter()
|
|
|
|
{
|
|
|
|
ParticleDemo::onEnter();
|
|
|
|
|
2013-07-08 18:11:32 +08:00
|
|
|
_color->setColor(Color3B::BLUE);
|
2013-06-15 14:03:30 +08:00
|
|
|
this->removeChild(_background, true);
|
2014-07-10 00:45:27 +08:00
|
|
|
_background = nullptr;
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
_emitter = ParticleSystemQuad::create("Particles/BoilingFoam.plist");
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->retain();
|
2012-06-15 15:10:40 +08:00
|
|
|
// Particle Designer "normal" blend func causes black halo on premul textures (ignores multiplication)
|
metal support for cocos2d-x (#19305)
* remove deprecated files
* remove some deprecated codes
* remove more deprecated codes
* remove ui deprecated codes
* remove more deprecated codes
* remove deprecated codes in ccmenuitem
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes
* remove more deprecated codes
* remove more deprecated codes
* remove vr related codes and ignore some modules
* remove allocator
* remove some config
* 【Feature】add back-end project file
* [Feature] add back-end file
* add pipeline descriptor and shader cache
* [Feature] support sprite for backend
* [Feature] remove unneeded code
* [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture
* [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture
* [Feature] remove macro define to .cpp file
* [Feature] add log info
* [Feature] add PipelineDescriptor for TriangleCommand
* [Feature] add PipelineDescriptor object as member of TriangleCommand
* [Feature] add getPipelineDescriptor method
* add renderbackend
* complete pipeline descriptor
* [Feature] add viewport in RenderCommand
* set viewport when rendrering
* [Feature] occur error when using RendererBackend, to be fixed.
* a workaround to fix black screen on macOS 10.14 (#19090)
* add rendererbackend init function
* fix typo
* [Feature] modify testFile
* [BugFix] modify shader path
* [Feature] set default viewport
* fix projection
* [Feature] modify log info
* [BugFix] change viewport data type to int
* [BugFix] add BindGroup to PipelienDescriptor
* [BugFix] change a_position to vec3 in sprite.vert
* [BugFix] set vertexLayout according to V3F_C4B_T2F structure
* [Feature] revert a_position to vec4
* [Feature] renderer should not use gl codes directly
* [Feature] it's better not use default value parameter
* fix depth test setting
* rendererbackend -> renderer
* clear color and depth at begin
* add metal backend
* metal support normalized attribute
* simplify codes
* update external
* add render pass desctriptor in pipeline descriptor
* fix warnings
* fix crash and memeory leak
* refactor Texture2D
* put pipeline descriptor into render command
* simplify codes
* [Feature] update Sprite
* fix crash when closing app
* [Feature] update SpriteBatchNode and TextureAtlas
* support render texture(not finish)
* [Feature] remove unused code
* make tests work on mac
* fix download-deps path error
* make tests work on iOS
* [Feature] support ttf under normal label effect
* refactor triangle command processing
* let renderer handle more common commands
* refactor backend
* make render texture work
* [Feature] refactor backend for GL
* [Feature]Renaming to make it easy to understand
* [Feature] change warp mode to CLAMP_TO_EDGE
* fix ghost
* simplify visit render queue logic
* support progress timer without rial mode
* support partcile system
* Feature/update label (#149)
* [BugFix] fix compile error
* [Feature] support outline effect in ios
* [Feature] add shader file
* [BugFix] fix begin and end RenderPass
* [Feature] update CustomCommand
* [Feature] revert project.pbxproj
* [Feature] simplify codes
* [BugFix] pack AI88 to RGBA8888 only when outline enable
* [Feature] support shadow effect in Label
* [Feature] support BMFont
* [Feature] support glow effect
* [Feature] simplify shader files
* LabelAtlas work
* handle blend function correctly
* support tile map
* don't share buffer in metal
* alloc buffer size as needed
* support more tilemap
* Merge branch 'minggo/metal-support' into feature/updateLabel
* minggo/metal-support:
support tile map
handle blend function correctly
LabelAtlas work
Feature/update label (#149)
support partcile system
# Conflicts:
# cocos/2d/CCLabel.cpp
# cocos/2d/CCSprite.cpp
# cocos/2d/CCSpriteBatchNode.cpp
# cocos/renderer/CCQuadCommand.cpp
# cocos/renderer/CCQuadCommand.h
* render texture work without saving file
* use global viewport
* grid3d works
* remove grabber
* tiled3d works
* [BugFix] fix label bug
* [Feature] add updateSubData for buffer
* [Feature] remove setVertexCount
* support depth test
* add callback command
* [Feature] add UITest
* [Feature] update UITest
* [Feature] remove unneeded codes
* fix custom command issue
* fix layer color blend issue
* [BugFix] fix iOS compile error
* [Feature] remove unneeded codes
* [Feature] fix updateVertexBuffer
* layerradial works
* add draw test back
* fix batch issue
* fix compiling error
* [BugFix] support ETC1
* [BugFix] get the correct pipelineDescriptor
* [BugFix] skip draw when backendTexture nullptr
* clipping node support
* [Feature] add shader files
* fix stencil issue in metal
* [Feature] update UILayoutTest
* [BugFix] skip drawing when vertexCount is zero
* refactor renderer
* add set global z order for stencil manager commands
* fix warnings caused by type
* remove viewport in render command
* [Feature] fix warnings caused by type
* [BugFix] clear vertexCount and indexCount for CustomComand when needed
* [Feature] update clear for CustomCommand
* ios use metal
* fix viewport issue
* fix LayerColorGradient crash
* [cmake] transport to android and windows (#160)
* save point 1
* compile on windows
* run on android
* revert useless change
* android set CC_ENABLE_CACHE_TEXTURE_DATA to 1
* add initGlew
* fix android crash
* add TODO new-renderer
* review update
* revert onGLFWWindowPosCallback
* fix android compiling error
* Impl progress radial (#162)
* progresstimer add radial impl
* default drawType to element
* dec invoke times of createVertexBuffer (#163)
* support depth/stencil format for gl backend
* simplify progress timer codes
* support motionstreak, effect is wrong
* fix motionstreak issue
* [Feature] update Scissor Test (#161)
* [Feature] update Scissor Test
* [Feature] update ScissorTest
* [Feature] rename function
* [Feature] get constant reference if needed
* [Feature] show render status (#164)
* improve performance
* fix depth state
* fill error that triangle vertex/index number bigger than buffer
* fix compiline error in release mode
* fix buffer conflict between CPU and GPU on iOS/macOS
* Renderer refactor (#165)
* use one vertes/index buffer with opengl
* fix error on windows
* custom command support index format config
* CCLayer: compact vertex data structure
* update comment
* fix doc
* support fast tilemap
* pass index format instead
* fix some wrong effect
* fix render texture error
* fix texture per-element size
* fix texture format error
* BlendFunc type refactor, GLenum -> backend::BlendFactor (#167)
* BlendFunc use backend::BlendFactor as inner field
* update comments
* use int to replace GLenum
* update xcode project fiel
* rename to GLBlendConst
* add ccConstants.h
* update xcode project file
* update copyright
* remove primitive command
* remove CCPrimitive.cpp/.h
* remove deprecated files
* remove unneeded files
* remove multiple view support
* remove multiple view support
* remove the usage of frame buffer in camera
* director don't use frame buffer
* remove FrameBuffer
* remove BatchCommand
* add some api reference
* add physics2d back
* fix crash when close app on mac
* improve render texture
* fix rendertexture issue
* fix rendertexture issue
* simplify codes
* CMake support for mac & ios (#169)
* update cmake
* fix compile error
* update 3rd libs version
* remove CCThread.h/.cpp
* remove ccthread
* use audio engine to implement simple audio engine
* remove unneeded codes
* remove deprecated codes
* remove winrt macro
* remove CC_USE_WIC
* set partcile blend function in more elegant way
* remove unneeded codes
* remove unneeded codes
* cmake works on windows
* update project setting
* improve performance
* GLFloat -> float
* sync v3 cmake improvements into metal-support (#172)
* pick: modern cmake, compile definitions improvement (#19139)
* modern cmake, use target_compile_definitions partly
* simplify macro define, remove USE_*
* modern cmake, macro define
* add physics 2d macro define into ccConfig.h
* remove USE_CHIPMUNK macro in build.gradle
* remove CocosSelectModule.cmake
* shrink useless define
* simplify compile options config, re-add if necessary
* update external for tmp CI test
* un-quote target_compile_options value
* add "-g" parameter only when debug mode
* keep single build type when generator Xcode & VS projecy
* update external for tmp CI tes
* add static_cast<char>(-1), fix -Wc++11-narrowing
* simplify win32 compile define
* not modify code, only improve compile options
# Conflicts:
# .gitignore
# cmake/Modules/CocosConfigDepend.cmake
# cocos/CMakeLists.txt
# external/config.json
# tests/cpp-tests/CMakeLists.txt
* modern cmake, improve cmake_compiler_flags (#19145)
* cmake_compiler_flags
* Fix typo
* Fix typo2
* Remove chanages from Android.mk
* correct lua template cmake build (#19149)
* don't add -Wno-deprecated into jsb target
* correct lua template cmake build
* fix win32 lua template compile error
* prevent cmake in-source-build friendly (#19151)
* pick: Copy resources to "Resources/" on win32 like in linux configuration
* add "/Z7" for cpp-tests on windows
* [cmake] fix iOS xcode property setting failed (#19208)
* fix iOS xcode property setting failed
* use search_depend_libs_recursive at dlls collect
* fix typo
* [cmake] add find_host_library into iOS toolchain file (#19230)
* pick: [lua android] use luajit & template cmake update (#19239)
* increase cmake stability , remove tests/CMakeLists.txt (#19261)
* cmake win32 Precompiled header (#19273)
* Precompiled header
* Fix
* Precompiled header for cocos
* Precompiled header jscocos2d
* Fix for COCOS2D_DEBUG is always 1 on Android (#19291)
Related #19289
* little build fix, tests cpp-tests works on mac
* sync v3 build related codes into metal-support (#173)
* strict initialization for std::array
* remove proj.win32 project configs
* modern cmake, cmake_cleanup_remove_unused_variables (#19146)
* Switch travis CI to xenial (#19207)
* Switch travis CI to xenial
* Remove language: android
* Set language: cpp
* Fix java problem
* Update sdkmanager
* Fix sdkmanger
* next sdkmanager fix
* Remove xenial from android
* revert to sdk-tools-{system}-3859397
* Remove linux cmake install
* Update before-install.sh
* Update .travis.yml
* Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212)
* Simplify install-deps-linux.sh
* Cleanup
* pick: install ninja
* update cocos2d-console submodule
* for metal-support alpha release, we only test cpp
* add HelloCpp into project(Cocos2d-x) for tmp test
* update extenal metal-support-4
* update uniform setting
* [Feature] update BindGroup
* [Feature] empty-test
* [Feature] cpp-test
* [Feature] fix GL compiler error
* [Feature] fix GL crash
* [Feature] empty-test
* [Feature] cpp-tests
* [feature] improve frameRate
* [feature] fix opengl compile error
* [feature] fix opengl compile error
* [BugFix] fix compute maxLocation error
* [Feature] update setting unifrom
* [Feature] fix namespace
* [Feature] remove unneeded code
* [Bugfix] fix project file
* [Feature] update review
* [texture2d] impl texture format support (#175)
* texture update
* update
* update texture
* commit
* compile on windows
* ddd
* rename
* rename methods
* no crash
* save gl
* save
* save
* rename
* move out pixel format convert functions
* metal crash
* update
* update android
* support gles compressed texture format
* support more compress format
* add more conversion methods
* ss
* save
* update conversion methods
* add PVRTC format support
* reformat
* add marco linux
* fix GL marcro
* pvrtc supported only by ios 8.0+
* remove unused cmake
* revert change
* refactor Texture2D::initWithData
* fix conversion log
* refactor Texture2D::initWithData
* remove some OpenGL constants for PVRTC
* add todo
* fix typo
* AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174)
* review cpp-tests, and fix part issues on start auto test
* sync png format fix: Node:Particle3D abnormal texture effects #19204
* fix cpp-tests SpritePolygon crash, wrong png format (#19170)
* fix wrong png convert format from sRGB to Gray
* erase plist index if all frames was erased
* test_A8.png have I8 format, fix it
* [CCSpriteCache] allow re-add plist & add testcase (#19175)
* allow re-add plist & add testcase
* remove comments/rename method/update testcase
* fix isSpriteFramesWithFileLoaded & add testcase
* remove used variable
* remove unused variable
* fix double free issues when js/lua-tests exit on iOS (#19236)
* disable part cases, AutoTest works without crash on mac
* update cocos2dx files json, to test cocos new next
* fix spritecache plist parsing issue (#19269)
* [linux] Fix FileUtils::getContents with folder (#19157)
* fix FileUtils::getContents on linux/mac
* use stat.st_mode
* simplify
* [CCFileUtils] win32 getFileSize (#19176)
* win32 getFileSize
* fix stat
* [cpp test-Android]20:FileUtils/2 change title (#19197)
* sync #19200
* sync #19231
* [android lua] improve performance of lua loader (#19234)
* [lua] improve performance of lua loader
* remove cache fix
* Revert "fix spritecache plist parsing issue (#19269)"
This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf.
* remove win32 project files ref in template.json
* add metal framework lnk ref into cpp template
* test on iOS, and disable part cases
* alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227)
* changes AudioCache to use alBufferData instead of alBufferDataStatic
(also makes test 19 faster to trigger openal bugs faster)
The original problem: CrashIfClientProvidedBogusAudioBufferList
https://github.com/cocos2d/cocos2d-x/issues/18948
is not happening anymore, but there's still a not very frequent issue
that makes OpenAL crash with a call stack like this.
AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList
It happes more frequently when the device is "cold", which means after
half an hour of not using the device (locked).
I could not find the actual source code for iOS OpenAL, so I used the
macOS versions:
https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html
They seem to use CAGuard.h to make sure the dead buffer list
has no threading issues. I'm worried because the CAGuard code I found
has macos and win32 define but no iOS, so I'm not sure. I guess the
iOS version is different and has the guard.
I could not find a place in the code that's unprotected by the locks
except the InitializeBufferMap() which should not be called more than
once from cocos, and there's a workaround in AudioEngine-impl for it.
I reduced the occurence of the CleanUpDeadBufferList crash by moving
the guard in ~AudioCache to cover the alDeleteBuffers call.
* remove hack method "setTimeout" on audio
* AutoTest works on iOS
* support set ios deployment target for root project
* enable all texture2d cases, since Jiang have fixed
* add CCTextureUtils to xcode project file (#176)
* add leak cases for SpriteFrameCache (#177)
* re-add SpriteFrameCache cases
* update template file json
* Update SpriteFrameCacheTest.cpp
* fix compiling error
2019-01-18 15:08:25 +08:00
|
|
|
//this->emitter.blendFunc = (BlendFunc){ BlendFactor::SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA };
|
2012-06-15 15:10:40 +08:00
|
|
|
|
|
|
|
// Cocos2d "normal" blend func for premul causes alpha to be ignored (oversaturates colors)
|
2013-07-26 04:36:19 +08:00
|
|
|
_emitter->setBlendFunc( BlendFunc::ALPHA_PREMULTIPLIED );
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2013-07-23 20:47:19 +08:00
|
|
|
CCASSERT(_emitter->isOpacityModifyRGB(), "Particle texture does not have premultiplied alpha, test is useless");
|
2012-06-15 15:10:40 +08:00
|
|
|
|
|
|
|
// Toggle next line to see old behavior
|
|
|
|
// this->emitter.opacityModifyRGB = NO;
|
|
|
|
|
2014-03-25 11:36:35 +08:00
|
|
|
_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));
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
this->addChild(_emitter, 10);
|
2014-06-04 10:39:18 +08:00
|
|
|
_hasEmitter = true;
|
2014-03-24 18:08:55 +08:00
|
|
|
|
2017-03-23 09:30:42 +08:00
|
|
|
schedule(CC_SCHEDULE_SELECTOR(PremultipliedAlphaTest::readdParticle), 1.0f);
|
2012-06-15 15:10:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// PremultipliedAlphaTest2
|
|
|
|
|
|
|
|
void PremultipliedAlphaTest2::onEnter()
|
|
|
|
{
|
|
|
|
ParticleDemo::onEnter();
|
|
|
|
|
2013-07-08 18:11:32 +08:00
|
|
|
_color->setColor(Color3B::BLACK);
|
2013-06-15 14:03:30 +08:00
|
|
|
this->removeChild(_background, true);
|
2014-07-10 00:45:27 +08:00
|
|
|
_background = nullptr;
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
_emitter = ParticleSystemQuad::create("Particles/TestPremultipliedAlpha.plist");
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitter->retain();
|
|
|
|
this->addChild(_emitter ,10);
|
2012-06-15 15:10:40 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string PremultipliedAlphaTest2::title() const
|
2012-06-12 15:40:31 +08:00
|
|
|
{
|
2014-03-24 18:20:11 +08:00
|
|
|
return "premultiplied alpha 2";
|
2012-06-12 15:40:31 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string PremultipliedAlphaTest2::subtitle() const
|
2012-06-15 15:10:40 +08:00
|
|
|
{
|
2014-03-24 18:20:11 +08:00
|
|
|
return "Arrows should be faded";
|
2012-06-15 15:10:40 +08:00
|
|
|
}
|
2012-04-04 21:58:04 +08:00
|
|
|
|
2014-02-11 20:33:36 +08:00
|
|
|
|
|
|
|
// Issue3990
|
|
|
|
|
|
|
|
void Issue3990::onEnter()
|
|
|
|
{
|
|
|
|
ParticleDemo::onEnter();
|
|
|
|
|
|
|
|
_color->setColor(Color3B::BLACK);
|
|
|
|
this->removeChild(_background, true);
|
2014-07-10 00:45:27 +08:00
|
|
|
_background = nullptr;
|
2014-02-11 20:33:36 +08:00
|
|
|
|
|
|
|
_emitter = ParticleSystemQuad::create("Particles/Spiral.plist");
|
|
|
|
|
|
|
|
_emitter->setPositionType(ParticleSystem::PositionType::GROUPED);
|
|
|
|
_emitter->setTotalParticles(1000);
|
2014-04-17 08:15:43 +08:00
|
|
|
_emitter->setEmissionRate(_emitter->getTotalParticles() / _emitter->getLife());
|
2014-02-11 20:33:36 +08:00
|
|
|
_emitter->setPosition(VisibleRect::center());
|
|
|
|
|
|
|
|
_emitter->retain();
|
|
|
|
this->addChild(_emitter ,10);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Issue3990::title() const
|
|
|
|
{
|
|
|
|
return "Issue3990, setTotalParticle should work";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Issue3990::subtitle() const
|
|
|
|
{
|
|
|
|
return "Show '998' or '999' at bottom right side";
|
|
|
|
}
|
|
|
|
|
2014-03-01 14:03:36 +08:00
|
|
|
|
2014-03-27 17:06:26 +08:00
|
|
|
// ParticleVisibleTest
|
|
|
|
void ParticleVisibleTest::onEnter()
|
|
|
|
{
|
|
|
|
ParticleDemo::onEnter();
|
|
|
|
|
|
|
|
_emitter = ParticleFireworks::create();
|
|
|
|
_emitter->retain();
|
|
|
|
_background->addChild(_emitter, 10);
|
|
|
|
|
|
|
|
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_stars1) );
|
|
|
|
|
2014-10-04 00:38:36 +08:00
|
|
|
schedule(CC_SCHEDULE_SELECTOR(ParticleVisibleTest::callback), 1);
|
2014-03-27 17:06:26 +08:00
|
|
|
|
|
|
|
setEmitterPosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ParticleVisibleTest::title() const
|
|
|
|
{
|
|
|
|
return "Issue4573";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ParticleVisibleTest::subtitle() const
|
|
|
|
{
|
|
|
|
return "Visible enable/disable";
|
|
|
|
}
|
|
|
|
|
|
|
|
void ParticleVisibleTest::callback(float delta)
|
|
|
|
{
|
|
|
|
_emitter->setVisible(!_emitter->isVisible());
|
|
|
|
}
|
|
|
|
|
2014-03-01 14:03:36 +08:00
|
|
|
//
|
|
|
|
// ParticleAutoBatching
|
|
|
|
//
|
|
|
|
void ParticleAutoBatching::onEnter()
|
|
|
|
{
|
|
|
|
ParticleDemo::onEnter();
|
|
|
|
|
|
|
|
_color->setColor(Color3B::BLACK);
|
|
|
|
this->removeChild(_background, true);
|
2014-07-10 00:45:27 +08:00
|
|
|
_background = nullptr;
|
2014-03-01 14:03:36 +08:00
|
|
|
|
|
|
|
Size s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
for(int i=0; i<10; i++) {
|
|
|
|
auto particle = ParticleSystemQuad::create("Particles/SmallSun.plist");
|
|
|
|
particle->setTotalParticles(100);
|
2014-05-15 01:07:09 +08:00
|
|
|
particle->setPosition(Vec2(i*s.width/11, s.height/2));
|
2014-03-01 14:03:36 +08:00
|
|
|
this->addChild(particle ,10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ParticleAutoBatching::title() const
|
|
|
|
{
|
|
|
|
return "AutoBatching";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ParticleAutoBatching::subtitle() const
|
|
|
|
{
|
|
|
|
return "All 10 particles should be drawin in one batch";
|
|
|
|
}
|
|
|
|
|
2014-07-29 11:21:11 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// 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 );
|
|
|
|
});
|
2017-03-27 10:50:41 +08:00
|
|
|
add->setFontSizeObj(20);
|
2014-07-29 11:21:11 +08:00
|
|
|
add->setPosition(Vec2(0, 25));
|
2017-03-27 10:50:41 +08:00
|
|
|
|
2014-07-29 11:21:11 +08:00
|
|
|
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));
|
2017-03-27 10:50:41 +08:00
|
|
|
remove->setFontSizeObj(20);
|
2014-07-29 11:21:11 +08:00
|
|
|
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2015-06-12 15:39:57 +08:00
|
|
|
void ParticleIssue12310::onEnter()
|
|
|
|
{
|
|
|
|
ParticleDemo::onEnter();
|
|
|
|
|
|
|
|
_color->setColor(Color3B::BLACK);
|
|
|
|
removeChild(_background, true);
|
|
|
|
_background = nullptr;
|
|
|
|
|
|
|
|
auto winSize = Director::getInstance()->getWinSize();
|
2014-02-11 20:33:36 +08:00
|
|
|
|
2015-06-12 15:39:57 +08:00
|
|
|
auto particle = ParticleSystemQuad::create("Particles/BoilingFoam.plist");
|
|
|
|
particle->setPosition(Vec2(winSize.width * 0.35f, winSize.height * 0.5f));
|
|
|
|
addChild(particle);
|
|
|
|
|
|
|
|
_emitter = particle;
|
2015-06-23 11:00:23 +08:00
|
|
|
_emitter->retain();
|
2015-06-12 15:39:57 +08:00
|
|
|
|
|
|
|
auto particle2 = ParticleSystemQuad::create("Particles/BoilingFoamStar.plist");
|
|
|
|
particle2->setPosition(Vec2(winSize.width * 0.65f, winSize.height * 0.5f));
|
|
|
|
addChild(particle2);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ParticleIssue12310::subtitle() const
|
|
|
|
{
|
|
|
|
return "You should see two Particle Emitters using different texture.";
|
|
|
|
}
|
2017-01-12 11:48:30 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ParticleSpriteFrame
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ParticleSpriteFrame::onEnter()
|
|
|
|
{
|
|
|
|
ParticleDemo::onEnter();
|
|
|
|
|
|
|
|
_emitter = ParticleSmoke::create();
|
|
|
|
_emitter->retain();
|
|
|
|
_background->addChild(_emitter, 10);
|
|
|
|
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Particles/SpriteFrame.plist");
|
|
|
|
|
|
|
|
_emitter->setDisplayFrame( SpriteFrameCache::getInstance()->getSpriteFrameByName("dot.png") );
|
|
|
|
|
|
|
|
setEmitterPosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ParticleSpriteFrame::title() const
|
|
|
|
{
|
|
|
|
return "Particle from SpriteFrame";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ParticleSpriteFrame::subtitle() const
|
|
|
|
{
|
|
|
|
return "Should not use entire texture atlas";
|
|
|
|
}
|