2012-04-19 14:35:52 +08:00
|
|
|
#include "PerformanceParticleTest.h"
|
|
|
|
|
|
|
|
|
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-07-23 08:25:44 +08:00
|
|
|
ParticleMainScene* scene = (ParticleMainScene*)getParent();
|
|
|
|
int subTest = scene->getSubTestNum();
|
|
|
|
int parNum = scene->getParticlesNum();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
ParticleMainScene* pNewScene = NULL;
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
switch (_curCase)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
pNewScene = new ParticlePerformTest1;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
pNewScene = new ParticlePerformTest2;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
pNewScene = new ParticlePerformTest3;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
pNewScene = new ParticlePerformTest4;
|
|
|
|
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-07-12 06:24:23 +08:00
|
|
|
Size 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);
|
|
|
|
MenuItemFont *decrease = MenuItemFont::create(" - ", [&](Object *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));
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont *increase = MenuItemFont::create(" + ", [&](Object *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
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Menu *menu = Menu::create(decrease, increase, NULL);
|
2011-03-25 13:59:08 +08:00
|
|
|
menu->alignItemsHorizontally();
|
2013-07-12 14:11:55 +08:00
|
|
|
menu->setPosition(Point(s.width/2, s.height/2+15));
|
2011-03-25 13:59:08 +08:00
|
|
|
addChild(menu, 1);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
LabelTTF *infoLabel = LabelTTF::create("0 nodes", "Marker Felt", 30);
|
2013-07-05 16:49:22 +08:00
|
|
|
infoLabel->setColor(Color3B(0,200,20));
|
2013-07-12 14:11:55 +08:00
|
|
|
infoLabel->setPosition(Point(s.width/2, s.height - 90));
|
2011-03-25 13:59:08 +08:00
|
|
|
addChild(infoLabel, 1, kTagInfoLayer);
|
|
|
|
|
|
|
|
// particles on stage
|
2013-06-20 14:17:10 +08:00
|
|
|
LabelAtlas *labelAtlas = LabelAtlas::create("0000", "fps_images.png", 12, 32, '.');
|
2011-03-25 13:59:08 +08:00
|
|
|
addChild(labelAtlas, 0, kTagLabelAtlas);
|
2013-07-12 14:11:55 +08:00
|
|
|
labelAtlas->setPosition(Point(s.width-66,50));
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
// Next Prev Test
|
2013-07-24 06:20:22 +08:00
|
|
|
ParticleMenuLayer* menuLayer = new ParticleMenuLayer(true, TEST_COUNT, s_nParCurIdx);
|
|
|
|
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);
|
|
|
|
Menu* 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-06-20 14:17:10 +08:00
|
|
|
MenuItemFont* 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();
|
2013-07-12 14:11:55 +08:00
|
|
|
pSubMenu->setPosition(Point(s.width/2, 80));
|
2011-03-25 13:59:08 +08:00
|
|
|
addChild(pSubMenu, 2);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
LabelTTF *label = LabelTTF::create(title().c_str(), "Arial", 40);
|
2011-03-25 13:59:08 +08:00
|
|
|
addChild(label, 1);
|
2013-07-12 14:11:55 +08:00
|
|
|
label->setPosition(Point(s.width/2, s.height-32));
|
2013-07-05 16:49:22 +08:00
|
|
|
label->setColor(Color3B(255,255,40));
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
updateQuantityLabel();
|
|
|
|
createParticleSystem();
|
|
|
|
|
|
|
|
schedule(schedule_selector(ParticleMainScene::step));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ParticleMainScene::title()
|
|
|
|
{
|
|
|
|
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-06-20 14:17:10 +08:00
|
|
|
LabelAtlas *atlas = (LabelAtlas*) getChildByTag(kTagLabelAtlas);
|
|
|
|
ParticleSystem *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-06-20 14:17:10 +08:00
|
|
|
ParticleSystem *particleSystem = NULL;
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Tests:
|
|
|
|
* 1: Point Particle System using 32-bit textures (PNG)
|
|
|
|
* 2: Point Particle System using 16-bit textures (PNG)
|
|
|
|
* 3: Point Particle System using 8-bit textures (PNG)
|
|
|
|
* 4: Point Particle System using 4-bit textures (PVRTC)
|
|
|
|
|
|
|
|
* 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-07-12 06:24:23 +08:00
|
|
|
Texture2D *texture = TextureCache::getInstance()->addImage("Images/fire.png");
|
|
|
|
TextureCache::getInstance()->removeTexture(texture);
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
//TODO: if (subtestNumber <= 3)
|
|
|
|
// {
|
2013-06-20 14:17:10 +08:00
|
|
|
// particleSystem = new ParticleSystemPoint();
|
2012-04-19 14:35:52 +08:00
|
|
|
// }
|
|
|
|
// else
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
particleSystem = new ParticleSystemQuad();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
switch( subtestNumber)
|
|
|
|
{
|
|
|
|
case 1:
|
2013-06-20 14:17:10 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(kTexture2DPixelFormat_RGBA8888);
|
2011-03-25 13:59:08 +08:00
|
|
|
particleSystem->initWithTotalParticles(quantityParticles);
|
2013-07-12 06:24:23 +08:00
|
|
|
particleSystem->setTexture(TextureCache::getInstance()->addImage("Images/fire.png"));
|
2011-03-25 13:59:08 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2013-06-20 14:17:10 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(kTexture2DPixelFormat_RGBA4444);
|
2011-03-25 13:59:08 +08:00
|
|
|
particleSystem->initWithTotalParticles(quantityParticles);
|
2013-07-12 06:24:23 +08:00
|
|
|
particleSystem->setTexture(TextureCache::getInstance()->addImage("Images/fire.png"));
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
2011-03-25 13:59:08 +08:00
|
|
|
case 3:
|
2013-06-20 14:17:10 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(kTexture2DPixelFormat_A8);
|
2011-03-25 13:59:08 +08:00
|
|
|
particleSystem->initWithTotalParticles(quantityParticles);
|
2013-07-12 06:24:23 +08:00
|
|
|
particleSystem->setTexture(TextureCache::getInstance()->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-07-12 06:24:23 +08:00
|
|
|
// particleSystem->setTexture(TextureCache::getInstance()->addImage("Images/fire.png"));
|
2012-04-19 14:35:52 +08:00
|
|
|
// break;
|
2011-03-25 13:59:08 +08:00
|
|
|
case 4:
|
2013-06-20 14:17:10 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(kTexture2DPixelFormat_RGBA8888);
|
2011-03-25 13:59:08 +08:00
|
|
|
particleSystem->initWithTotalParticles(quantityParticles);
|
2013-07-12 06:24:23 +08:00
|
|
|
particleSystem->setTexture(TextureCache::getInstance()->addImage("Images/fire.png"));
|
2011-03-25 13:59:08 +08:00
|
|
|
break;
|
|
|
|
case 5:
|
2013-06-20 14:17:10 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(kTexture2DPixelFormat_RGBA4444);
|
2011-03-25 13:59:08 +08:00
|
|
|
particleSystem->initWithTotalParticles(quantityParticles);
|
2013-07-12 06:24:23 +08:00
|
|
|
particleSystem->setTexture(TextureCache::getInstance()->addImage("Images/fire.png"));
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
2011-03-25 13:59:08 +08:00
|
|
|
case 6:
|
2013-06-20 14:17:10 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(kTexture2DPixelFormat_A8);
|
2011-03-25 13:59:08 +08:00
|
|
|
particleSystem->initWithTotalParticles(quantityParticles);
|
2013-07-12 06:24:23 +08:00
|
|
|
particleSystem->setTexture(TextureCache::getInstance()->addImage("Images/fire.png"));
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
// case 8:
|
|
|
|
// particleSystem->initWithTotalParticles(quantityParticles);
|
2013-06-20 14:17:10 +08:00
|
|
|
// ////---- particleSystem.texture = [[TextureCache sharedTextureCache] addImage:@"fire.pvr"];
|
2013-07-12 06:24:23 +08:00
|
|
|
// particleSystem->setTexture(TextureCache::getInstance()->addImage("Images/fire.png"));
|
2012-04-19 14:35:52 +08:00
|
|
|
// break;
|
2011-03-25 13:59:08 +08:00
|
|
|
default:
|
|
|
|
particleSystem = NULL;
|
|
|
|
CCLOG("Shall not happen!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
addChild(particleSystem, 0, kTagParticleSystem);
|
|
|
|
particleSystem->release();
|
|
|
|
|
|
|
|
doTest();
|
2011-04-20 15:34:33 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// restore the default pixel format
|
2013-06-20 14:17:10 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(kTexture2DPixelFormat_RGBA8888);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void ParticleMainScene::testNCallback(Object* pSender)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
subtestNumber = ((Node*)pSender)->getTag();
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
ParticleMenuLayer* menu = (ParticleMenuLayer*)getChildByTag(kTagMenuLayer);
|
|
|
|
menu->restartCallback(pSender);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ParticleMainScene::updateQuantityLabel()
|
|
|
|
{
|
|
|
|
if( quantityParticles != lastRenderedCount )
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
LabelTTF *infoLabel = (LabelTTF *) 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
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
2011-03-25 13:59:08 +08:00
|
|
|
std::string ParticlePerformTest1::title()
|
|
|
|
{
|
|
|
|
char str[20] = {0};
|
|
|
|
sprintf(str, "A (%d) size=4", subtestNumber);
|
|
|
|
std::string strRet = str;
|
|
|
|
return strRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ParticlePerformTest1::doTest()
|
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2013-06-20 14:17:10 +08:00
|
|
|
ParticleSystem *particleSystem = (ParticleSystem*)getChildByTag(kTagParticleSystem);
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
// duration
|
|
|
|
particleSystem->setDuration(-1);
|
|
|
|
|
|
|
|
// gravity
|
2013-07-12 14:11:55 +08:00
|
|
|
particleSystem->setGravity(Point(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
|
2013-07-12 14:11:55 +08:00
|
|
|
particleSystem->setPosition(Point(s.width/2, 100));
|
|
|
|
particleSystem->setPosVar(Point(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
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
2011-03-25 13:59:08 +08:00
|
|
|
std::string ParticlePerformTest2::title()
|
|
|
|
{
|
|
|
|
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-07-12 06:24:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2013-06-20 14:17:10 +08:00
|
|
|
ParticleSystem *particleSystem = (ParticleSystem*) getChildByTag(kTagParticleSystem);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// duration
|
|
|
|
particleSystem->setDuration(-1);
|
|
|
|
|
|
|
|
// gravity
|
2013-07-12 14:11:55 +08:00
|
|
|
particleSystem->setGravity(Point(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
|
2013-07-12 14:11:55 +08:00
|
|
|
particleSystem->setPosition(Point(s.width/2, 100));
|
|
|
|
particleSystem->setPosVar(Point(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
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
2011-03-25 13:59:08 +08:00
|
|
|
std::string ParticlePerformTest3::title()
|
|
|
|
{
|
|
|
|
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-07-12 06:24:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2013-06-20 14:17:10 +08:00
|
|
|
ParticleSystem *particleSystem = (ParticleSystem*)getChildByTag(kTagParticleSystem);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// duration
|
|
|
|
particleSystem->setDuration(-1);
|
|
|
|
|
|
|
|
// gravity
|
2013-07-12 14:11:55 +08:00
|
|
|
particleSystem->setGravity(Point(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
|
2013-07-12 14:11:55 +08:00
|
|
|
particleSystem->setPosition(Point(s.width/2, 100));
|
|
|
|
particleSystem->setPosVar(Point(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
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
2011-03-25 13:59:08 +08:00
|
|
|
std::string ParticlePerformTest4::title()
|
|
|
|
{
|
|
|
|
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-07-12 06:24:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2013-06-20 14:17:10 +08:00
|
|
|
ParticleSystem *particleSystem = (ParticleSystem*) getChildByTag(kTagParticleSystem);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// duration
|
|
|
|
particleSystem->setDuration(-1);
|
|
|
|
|
|
|
|
// gravity
|
2013-07-12 14:11:55 +08:00
|
|
|
particleSystem->setGravity(Point(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
|
2013-07-12 14:11:55 +08:00
|
|
|
particleSystem->setPosition(Point(s.width/2, 100));
|
|
|
|
particleSystem->setPosVar(Point(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()
|
|
|
|
{
|
2013-07-23 08:25:44 +08:00
|
|
|
ParticleMainScene* scene = new ParticlePerformTest1;
|
|
|
|
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
|
|
|
}
|