2012-04-19 14:35:52 +08:00
|
|
|
#include "PerformanceParticleTest.h"
|
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
USING_NS_CC;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2011-03-25 13:59:08 +08:00
|
|
|
enum {
|
|
|
|
kTagInfoLayer = 1,
|
|
|
|
kTagMainLayer = 2,
|
|
|
|
kTagParticleSystem = 3,
|
|
|
|
kTagLabelAtlas = 4,
|
|
|
|
kTagMenuLayer = 1000,
|
|
|
|
|
|
|
|
TEST_COUNT = 4,
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
2011-03-25 13:59:08 +08:00
|
|
|
enum {
|
|
|
|
kMaxParticles = 14000,
|
2012-06-12 16:56:34 +08:00
|
|
|
kNodesIncrease = 500,
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int s_nParCurIdx = 0;
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// ParticleMenuLayer
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
ParticleMenuLayer::ParticleMenuLayer(bool bControlMenuVisible, int nMaxCases, int nCurCase)
|
|
|
|
: PerformBasicLayer(bControlMenuVisible, nMaxCases, nCurCase)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ParticleMenuLayer::showCurrentTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto scene = (ParticleMainScene*)getParent();
|
2013-07-23 08:25:44 +08:00
|
|
|
int subTest = scene->getSubTestNum();
|
|
|
|
int parNum = scene->getParticlesNum();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
ParticleMainScene* pNewScene = nullptr;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
switch (_curCase)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
case 0:
|
2014-08-28 07:31:57 +08:00
|
|
|
pNewScene = new (std::nothrow) ParticlePerformTest1;
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-08-28 07:31:57 +08:00
|
|
|
pNewScene = new (std::nothrow) ParticlePerformTest2;
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-08-28 07:31:57 +08:00
|
|
|
pNewScene = new (std::nothrow) ParticlePerformTest3;
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
case 3:
|
2014-08-28 07:31:57 +08:00
|
|
|
pNewScene = new (std::nothrow) ParticlePerformTest4;
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
s_nParCurIdx = _curCase;
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pNewScene)
|
|
|
|
{
|
|
|
|
pNewScene->initWithSubTest(subTest, parNum);
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(pNewScene);
|
2012-04-19 14:35:52 +08:00
|
|
|
pNewScene->release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// ParticleMainScene
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
2011-03-25 13:59:08 +08:00
|
|
|
void ParticleMainScene::initWithSubTest(int asubtest, int particles)
|
|
|
|
{
|
|
|
|
//srandom(0);
|
|
|
|
|
|
|
|
subtestNumber = asubtest;
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
lastRenderedCount = 0;
|
|
|
|
quantityParticles = particles;
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::setFontSize(65);
|
2014-02-20 10:53:49 +08:00
|
|
|
auto decrease = MenuItemFont::create(" - ", [&](Ref *sender) {
|
2013-06-08 08:21:11 +08:00
|
|
|
quantityParticles -= kNodesIncrease;
|
|
|
|
if( quantityParticles < 0 )
|
|
|
|
quantityParticles = 0;
|
|
|
|
|
|
|
|
updateQuantityLabel();
|
|
|
|
createParticleSystem();
|
|
|
|
});
|
2013-07-05 16:49:22 +08:00
|
|
|
decrease->setColor(Color3B(0,200,20));
|
2014-02-20 10:53:49 +08:00
|
|
|
auto increase = MenuItemFont::create(" + ", [&](Ref *sender) {
|
2013-06-08 08:21:11 +08:00
|
|
|
quantityParticles += kNodesIncrease;
|
|
|
|
if( quantityParticles > kMaxParticles )
|
|
|
|
quantityParticles = kMaxParticles;
|
|
|
|
|
|
|
|
updateQuantityLabel();
|
|
|
|
createParticleSystem();
|
|
|
|
});
|
2013-07-05 16:49:22 +08:00
|
|
|
increase->setColor(Color3B(0,200,20));
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto menu = Menu::create(decrease, increase, nullptr);
|
2011-03-25 13:59:08 +08:00
|
|
|
menu->alignItemsHorizontally();
|
2014-05-15 01:07:09 +08:00
|
|
|
menu->setPosition(Vec2(s.width/2, s.height/2+15));
|
2011-03-25 13:59:08 +08:00
|
|
|
addChild(menu, 1);
|
|
|
|
|
2014-04-09 23:31:05 +08:00
|
|
|
auto infoLabel = Label::createWithTTF("0 nodes", "fonts/Marker Felt.ttf", 30);
|
2013-07-05 16:49:22 +08:00
|
|
|
infoLabel->setColor(Color3B(0,200,20));
|
2014-05-15 01:07:09 +08:00
|
|
|
infoLabel->setPosition(Vec2(s.width/2, s.height - 90));
|
2011-03-25 13:59:08 +08:00
|
|
|
addChild(infoLabel, 1, kTagInfoLayer);
|
|
|
|
|
|
|
|
// particles on stage
|
2013-08-16 16:05:27 +08:00
|
|
|
auto labelAtlas = LabelAtlas::create("0000", "fps_images.png", 12, 32, '.');
|
2011-03-25 13:59:08 +08:00
|
|
|
addChild(labelAtlas, 0, kTagLabelAtlas);
|
2014-05-15 01:07:09 +08:00
|
|
|
labelAtlas->setPosition(Vec2(s.width-66,50));
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
// Next Prev Test
|
2014-08-28 07:31:57 +08:00
|
|
|
auto menuLayer = new (std::nothrow) ParticleMenuLayer(true, TEST_COUNT, s_nParCurIdx);
|
2013-07-24 06:20:22 +08:00
|
|
|
addChild(menuLayer, 1, kTagMenuLayer);
|
|
|
|
menuLayer->release();
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
// Sub Tests
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::setFontSize(40);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto pSubMenu = Menu::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
for (int i = 1; i <= 6; ++i)
|
|
|
|
{
|
|
|
|
char str[10] = {0};
|
|
|
|
sprintf(str, "%d ", i);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto itemFont = MenuItemFont::create(str, CC_CALLBACK_1(ParticleMainScene::testNCallback, this));
|
2012-04-19 14:35:52 +08:00
|
|
|
itemFont->setTag(i);
|
|
|
|
pSubMenu->addChild(itemFont, 10);
|
|
|
|
|
|
|
|
if (i <= 3)
|
|
|
|
{
|
2013-07-05 16:49:22 +08:00
|
|
|
itemFont->setColor(Color3B(200,20,20));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-05 16:49:22 +08:00
|
|
|
itemFont->setColor(Color3B(0,200,20));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
2011-03-25 13:59:08 +08:00
|
|
|
pSubMenu->alignItemsHorizontally();
|
2014-05-15 01:07:09 +08:00
|
|
|
pSubMenu->setPosition(Vec2(s.width/2, 80));
|
2011-03-25 13:59:08 +08:00
|
|
|
addChild(pSubMenu, 2);
|
|
|
|
|
2014-04-09 23:31:05 +08:00
|
|
|
auto label = Label::createWithTTF(title().c_str(), "fonts/arial.ttf", 32);
|
2011-03-25 13:59:08 +08:00
|
|
|
addChild(label, 1);
|
2014-05-15 01:07:09 +08:00
|
|
|
label->setPosition(Vec2(s.width/2, s.height-50));
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
updateQuantityLabel();
|
|
|
|
createParticleSystem();
|
|
|
|
|
2014-10-04 00:38:36 +08:00
|
|
|
schedule(CC_SCHEDULE_SELECTOR(ParticleMainScene::step));
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ParticleMainScene::title() const
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
return "No title";
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void ParticleMainScene::step(float dt)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto atlas = (LabelAtlas*) getChildByTag(kTagLabelAtlas);
|
|
|
|
auto emitter = (ParticleSystem*) getChildByTag(kTagParticleSystem);
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
char str[10] = {0};
|
|
|
|
sprintf(str, "%4d", emitter->getParticleCount());
|
|
|
|
atlas->setString(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ParticleMainScene::createParticleSystem()
|
|
|
|
{
|
2013-11-15 08:21:49 +08:00
|
|
|
ParticleSystemQuad *particleSystem = nullptr;
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Tests:
|
2014-05-15 01:07:09 +08:00
|
|
|
* 1: Vec2 Particle System using 32-bit textures (PNG)
|
|
|
|
* 2: Vec2 Particle System using 16-bit textures (PNG)
|
|
|
|
* 3: Vec2 Particle System using 8-bit textures (PNG)
|
|
|
|
* 4: Vec2 Particle System using 4-bit textures (PVRTC)
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
* 5: Quad Particle System using 32-bit textures (PNG)
|
|
|
|
* 6: Quad Particle System using 16-bit textures (PNG)
|
|
|
|
* 7: Quad Particle System using 8-bit textures (PNG)
|
|
|
|
* 8: Quad Particle System using 4-bit textures (PVRTC)
|
|
|
|
*/
|
|
|
|
removeChildByTag(kTagParticleSystem, true);
|
|
|
|
|
|
|
|
// remove the "fire.png" from the TextureCache cache.
|
2013-11-07 21:48:39 +08:00
|
|
|
auto texture = Director::getInstance()->getTextureCache()->addImage("Images/fire.png");
|
|
|
|
Director::getInstance()->getTextureCache()->removeTexture(texture);
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
//TODO: if (subtestNumber <= 3)
|
|
|
|
// {
|
2014-08-28 07:31:57 +08:00
|
|
|
// particleSystem = new (std::nothrow) ParticleSystemPoint();
|
2012-04-19 14:35:52 +08:00
|
|
|
// }
|
|
|
|
// else
|
|
|
|
{
|
2014-01-03 18:15:56 +08:00
|
|
|
particleSystem = ParticleSystemQuad::createWithTotalParticles(quantityParticles);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
switch( subtestNumber)
|
|
|
|
{
|
|
|
|
case 1:
|
2013-07-26 04:36:19 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
|
2013-11-07 21:48:39 +08:00
|
|
|
particleSystem->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png"));
|
2011-03-25 13:59:08 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2013-07-26 04:36:19 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
|
2013-11-07 21:48:39 +08:00
|
|
|
particleSystem->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png"));
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
2011-03-25 13:59:08 +08:00
|
|
|
case 3:
|
2013-07-26 04:36:19 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::A8);
|
2013-11-07 21:48:39 +08:00
|
|
|
particleSystem->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png"));
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
// case 4:
|
|
|
|
// particleSystem->initWithTotalParticles(quantityParticles);
|
2013-06-20 14:17:10 +08:00
|
|
|
// ////---- particleSystem.texture = [[TextureCache sharedTextureCache] addImage:@"fire.pvr"];
|
2013-11-07 21:48:39 +08:00
|
|
|
// particleSystem->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png"));
|
2012-04-19 14:35:52 +08:00
|
|
|
// break;
|
2011-03-25 13:59:08 +08:00
|
|
|
case 4:
|
2013-07-26 04:36:19 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
|
2013-11-07 21:48:39 +08:00
|
|
|
particleSystem->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png"));
|
2011-03-25 13:59:08 +08:00
|
|
|
break;
|
|
|
|
case 5:
|
2013-07-26 04:36:19 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
|
2013-11-07 21:48:39 +08:00
|
|
|
particleSystem->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png"));
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
2011-03-25 13:59:08 +08:00
|
|
|
case 6:
|
2013-07-26 04:36:19 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::A8);
|
2013-11-07 21:48:39 +08:00
|
|
|
particleSystem->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png"));
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
// case 8:
|
2013-06-20 14:17:10 +08:00
|
|
|
// ////---- particleSystem.texture = [[TextureCache sharedTextureCache] addImage:@"fire.pvr"];
|
2013-11-07 21:48:39 +08:00
|
|
|
// particleSystem->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png"));
|
2012-04-19 14:35:52 +08:00
|
|
|
// break;
|
2011-03-25 13:59:08 +08:00
|
|
|
default:
|
2014-07-10 00:45:27 +08:00
|
|
|
particleSystem = nullptr;
|
2011-03-25 13:59:08 +08:00
|
|
|
CCLOG("Shall not happen!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
addChild(particleSystem, 0, kTagParticleSystem);
|
|
|
|
|
|
|
|
doTest();
|
2011-04-20 15:34:33 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// restore the default pixel format
|
2013-07-26 04:36:19 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void ParticleMainScene::testNCallback(Ref* sender)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-07-26 06:53:24 +08:00
|
|
|
subtestNumber = static_cast<Node*>(sender)->getTag();
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
auto menu = static_cast<ParticleMenuLayer*>( getChildByTag(kTagMenuLayer) );
|
|
|
|
menu->restartCallback(sender);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ParticleMainScene::updateQuantityLabel()
|
|
|
|
{
|
|
|
|
if( quantityParticles != lastRenderedCount )
|
|
|
|
{
|
2014-03-26 23:33:58 +08:00
|
|
|
auto infoLabel = (Label *) getChildByTag(kTagInfoLayer);
|
2011-03-25 13:59:08 +08:00
|
|
|
char str[20] = {0};
|
|
|
|
sprintf(str, "%u particles", quantityParticles);
|
|
|
|
infoLabel->setString(str);
|
|
|
|
|
|
|
|
lastRenderedCount = quantityParticles;
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// ParticlePerformTest1
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ParticlePerformTest1::title() const
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
char str[20] = {0};
|
|
|
|
sprintf(str, "A (%d) size=4", subtestNumber);
|
|
|
|
std::string strRet = str;
|
|
|
|
return strRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ParticlePerformTest1::doTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
auto particleSystem = (ParticleSystem*)getChildByTag(kTagParticleSystem);
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
// duration
|
|
|
|
particleSystem->setDuration(-1);
|
|
|
|
|
|
|
|
// gravity
|
2014-05-15 01:07:09 +08:00
|
|
|
particleSystem->setGravity(Vec2(0,-90));
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
// angle
|
|
|
|
particleSystem->setAngle(90);
|
|
|
|
particleSystem->setAngleVar(0);
|
|
|
|
|
|
|
|
// radial
|
|
|
|
particleSystem->setRadialAccel(0);
|
|
|
|
particleSystem->setRadialAccelVar(0);
|
|
|
|
|
|
|
|
// speed of particles
|
|
|
|
particleSystem->setSpeed(180);
|
|
|
|
particleSystem->setSpeedVar(50);
|
|
|
|
|
|
|
|
// emitter position
|
2014-05-15 01:07:09 +08:00
|
|
|
particleSystem->setPosition(Vec2(s.width/2, 100));
|
|
|
|
particleSystem->setPosVar(Vec2(s.width/2,0));
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
// life of particles
|
|
|
|
particleSystem->setLife(2.0f);
|
|
|
|
particleSystem->setLifeVar(1);
|
|
|
|
|
|
|
|
// emits per frame
|
|
|
|
particleSystem->setEmissionRate(particleSystem->getTotalParticles() /particleSystem->getLife());
|
|
|
|
|
|
|
|
// color of particles
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F startColor(0.5f, 0.5f, 0.5f, 1.0f);
|
2011-03-25 13:59:08 +08:00
|
|
|
particleSystem->setStartColor(startColor);
|
|
|
|
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F startColorVar(0.5f, 0.5f, 0.5f, 1.0f);
|
2011-03-25 13:59:08 +08:00
|
|
|
particleSystem->setStartColorVar( startColorVar);
|
|
|
|
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F endColor(0.1f, 0.1f, 0.1f, 0.2f);
|
2011-03-25 13:59:08 +08:00
|
|
|
particleSystem->setEndColor(endColor);
|
|
|
|
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F endColorVar(0.1f, 0.1f, 0.1f, 0.2f);
|
2011-03-25 13:59:08 +08:00
|
|
|
particleSystem->setEndColorVar(endColorVar);
|
|
|
|
|
|
|
|
// size, in pixels
|
|
|
|
particleSystem->setEndSize(4.0f);
|
|
|
|
particleSystem->setStartSize(4.0f);
|
|
|
|
particleSystem->setEndSizeVar(0);
|
|
|
|
particleSystem->setStartSizeVar(0);
|
|
|
|
|
|
|
|
// additive
|
2012-06-15 15:10:40 +08:00
|
|
|
particleSystem->setBlendAdditive(false);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// ParticlePerformTest2
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ParticlePerformTest2::title() const
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
char str[20] = {0};
|
|
|
|
sprintf(str, "B (%d) size=8", subtestNumber);
|
|
|
|
std::string strRet = str;
|
|
|
|
return strRet;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ParticlePerformTest2::doTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
auto particleSystem = (ParticleSystem*) getChildByTag(kTagParticleSystem);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// duration
|
|
|
|
particleSystem->setDuration(-1);
|
|
|
|
|
|
|
|
// gravity
|
2014-05-15 01:07:09 +08:00
|
|
|
particleSystem->setGravity(Vec2(0,-90));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// angle
|
|
|
|
particleSystem->setAngle(90);
|
|
|
|
particleSystem->setAngleVar(0);
|
|
|
|
|
|
|
|
// radial
|
|
|
|
particleSystem->setRadialAccel(0);
|
|
|
|
particleSystem->setRadialAccelVar(0);
|
|
|
|
|
|
|
|
// speed of particles
|
|
|
|
particleSystem->setSpeed(180);
|
|
|
|
particleSystem->setSpeedVar(50);
|
|
|
|
|
|
|
|
// emitter position
|
2014-05-15 01:07:09 +08:00
|
|
|
particleSystem->setPosition(Vec2(s.width/2, 100));
|
|
|
|
particleSystem->setPosVar(Vec2(s.width/2,0));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// life of particles
|
|
|
|
particleSystem->setLife(2.0f);
|
|
|
|
particleSystem->setLifeVar(1);
|
|
|
|
|
|
|
|
// emits per frame
|
|
|
|
particleSystem->setEmissionRate(particleSystem->getTotalParticles() / particleSystem->getLife());
|
|
|
|
|
|
|
|
// color of particles
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F startColor(0.5f, 0.5f, 0.5f, 1.0f);
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setStartColor(startColor);
|
|
|
|
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F startColorVar(0.5f, 0.5f, 0.5f, 1.0f);
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setStartColorVar(startColorVar);
|
|
|
|
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F endColor(0.1f, 0.1f, 0.1f, 0.2f);
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setEndColor(endColor);
|
|
|
|
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F endColorVar(0.1f, 0.1f, 0.1f, 0.2f);
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setEndColorVar(endColorVar);
|
|
|
|
|
|
|
|
// size, in pixels
|
|
|
|
particleSystem->setEndSize(8.0f);
|
|
|
|
particleSystem->setStartSize(8.0f);
|
|
|
|
particleSystem->setEndSizeVar(0);
|
|
|
|
particleSystem->setStartSizeVar(0);
|
|
|
|
|
|
|
|
// additive
|
2012-06-15 15:10:40 +08:00
|
|
|
particleSystem->setBlendAdditive(false);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// ParticlePerformTest3
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ParticlePerformTest3::title() const
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
char str[20] = {0};
|
|
|
|
sprintf(str, "C (%d) size=32", subtestNumber);
|
|
|
|
std::string strRet = str;
|
|
|
|
return strRet;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ParticlePerformTest3::doTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
auto particleSystem = (ParticleSystem*)getChildByTag(kTagParticleSystem);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// duration
|
|
|
|
particleSystem->setDuration(-1);
|
|
|
|
|
|
|
|
// gravity
|
2014-05-15 01:07:09 +08:00
|
|
|
particleSystem->setGravity(Vec2(0,-90));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// angle
|
|
|
|
particleSystem->setAngle(90);
|
|
|
|
particleSystem->setAngleVar(0);
|
|
|
|
|
|
|
|
// radial
|
|
|
|
particleSystem->setRadialAccel(0);
|
|
|
|
particleSystem->setRadialAccelVar(0);
|
|
|
|
|
|
|
|
// speed of particles
|
|
|
|
particleSystem->setSpeed(180);
|
|
|
|
particleSystem->setSpeedVar(50);
|
|
|
|
|
|
|
|
// emitter position
|
2014-05-15 01:07:09 +08:00
|
|
|
particleSystem->setPosition(Vec2(s.width/2, 100));
|
|
|
|
particleSystem->setPosVar(Vec2(s.width/2,0));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// life of particles
|
|
|
|
particleSystem->setLife(2.0f);
|
|
|
|
particleSystem->setLifeVar(1);
|
|
|
|
|
|
|
|
// emits per frame
|
|
|
|
particleSystem->setEmissionRate(particleSystem->getTotalParticles() / particleSystem->getLife());
|
|
|
|
|
|
|
|
// color of particles
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F startColor(0.5f, 0.5f, 0.5f, 1.0f);
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setStartColor(startColor);
|
|
|
|
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F startColorVar(0.5f, 0.5f, 0.5f, 1.0f);
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setStartColorVar(startColorVar);
|
|
|
|
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F endColor(0.1f, 0.1f, 0.1f, 0.2f);
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setEndColor(endColor);
|
|
|
|
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F endColorVar(0.1f, 0.1f, 0.1f, 0.2f);
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setEndColorVar(endColorVar);
|
|
|
|
|
|
|
|
// size, in pixels
|
|
|
|
particleSystem->setEndSize(32.0f);
|
|
|
|
particleSystem->setStartSize(32.0f);
|
|
|
|
particleSystem->setEndSizeVar(0);
|
|
|
|
particleSystem->setStartSizeVar(0);
|
|
|
|
|
|
|
|
// additive
|
2012-06-15 15:10:40 +08:00
|
|
|
particleSystem->setBlendAdditive(false);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// ParticlePerformTest4
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ParticlePerformTest4::title() const
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
char str[20] = {0};
|
|
|
|
sprintf(str, "D (%d) size=64", subtestNumber);
|
|
|
|
std::string strRet = str;
|
|
|
|
return strRet;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ParticlePerformTest4::doTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
auto particleSystem = (ParticleSystem*) getChildByTag(kTagParticleSystem);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// duration
|
|
|
|
particleSystem->setDuration(-1);
|
|
|
|
|
|
|
|
// gravity
|
2014-05-15 01:07:09 +08:00
|
|
|
particleSystem->setGravity(Vec2(0,-90));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// angle
|
|
|
|
particleSystem->setAngle(90);
|
|
|
|
particleSystem->setAngleVar(0);
|
|
|
|
|
|
|
|
// radial
|
|
|
|
particleSystem->setRadialAccel(0);
|
|
|
|
particleSystem->setRadialAccelVar(0);
|
|
|
|
|
|
|
|
// speed of particles
|
|
|
|
particleSystem->setSpeed(180);
|
|
|
|
particleSystem->setSpeedVar(50);
|
|
|
|
|
|
|
|
// emitter position
|
2014-05-15 01:07:09 +08:00
|
|
|
particleSystem->setPosition(Vec2(s.width/2, 100));
|
|
|
|
particleSystem->setPosVar(Vec2(s.width/2,0));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// life of particles
|
|
|
|
particleSystem->setLife(2.0f);
|
|
|
|
particleSystem->setLifeVar(1);
|
|
|
|
|
|
|
|
// emits per frame
|
|
|
|
particleSystem->setEmissionRate(particleSystem->getTotalParticles() / particleSystem->getLife());
|
|
|
|
|
|
|
|
// color of particles
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F startColor(0.5f, 0.5f, 0.5f, 1.0f);
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setStartColor(startColor);
|
|
|
|
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F startColorVar(0.5f, 0.5f, 0.5f, 1.0f);
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setStartColorVar(startColorVar);
|
|
|
|
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F endColor(0.1f, 0.1f, 0.1f, 0.2f);
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setEndColor(endColor);
|
|
|
|
|
2013-07-07 21:08:14 +08:00
|
|
|
Color4F endColorVar(0.1f, 0.1f, 0.1f, 0.2f);
|
2012-04-19 14:35:52 +08:00
|
|
|
particleSystem->setEndColorVar(endColorVar);
|
|
|
|
|
|
|
|
// size, in pixels
|
|
|
|
particleSystem->setEndSize(64.0f);
|
|
|
|
particleSystem->setStartSize(64.0f);
|
|
|
|
particleSystem->setEndSizeVar(0);
|
|
|
|
particleSystem->setStartSizeVar(0);
|
|
|
|
|
|
|
|
// additive
|
2012-06-15 15:10:40 +08:00
|
|
|
particleSystem->setBlendAdditive(false);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void runParticleTest()
|
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
auto scene = new (std::nothrow) ParticlePerformTest1;
|
2013-07-23 08:25:44 +08:00
|
|
|
scene->initWithSubTest(1, kNodesIncrease);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
Director::getInstance()->replaceScene(scene);
|
|
|
|
scene->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|