From 9bdcdec60adc521620bf907455b69c5640c5fa7c Mon Sep 17 00:00:00 2001 From: songchengjiang Date: Tue, 3 Mar 2015 15:10:42 +0800 Subject: [PATCH] add test demo use particleSystemScaleVelocity --- .../ParticleUniverse/CCPUParticleSystem3D.cpp | 2 + .../CCPUParticleSystem3DTranslator.cpp | 24 ++++---- .../Classes/Particle3DTest/Particle3DTest.cpp | 56 +++++++++++++------ .../Classes/Particle3DTest/Particle3DTest.h | 13 +++++ 4 files changed, 67 insertions(+), 28 deletions(-) diff --git a/extensions/Particle3D/ParticleUniverse/CCPUParticleSystem3D.cpp b/extensions/Particle3D/ParticleUniverse/CCPUParticleSystem3D.cpp index 4e4ab247cb..ac4bef69fd 100755 --- a/extensions/Particle3D/ParticleUniverse/CCPUParticleSystem3D.cpp +++ b/extensions/Particle3D/ParticleUniverse/CCPUParticleSystem3D.cpp @@ -511,6 +511,8 @@ void PUParticleSystem3D::prepared() _prepared = true; _timeElapsedSinceStart = 0.0f; + if (_parentParticleSystem) + _particleSystemScaleVelocity = _parentParticleSystem->getParticleSystemScaleVelocity(); } notifyRescaled(getDerivedScale()); diff --git a/extensions/Particle3D/ParticleUniverse/CCPUParticleSystem3DTranslator.cpp b/extensions/Particle3D/ParticleUniverse/CCPUParticleSystem3DTranslator.cpp index fc04775fab..2db86054ca 100644 --- a/extensions/Particle3D/ParticleUniverse/CCPUParticleSystem3DTranslator.cpp +++ b/extensions/Particle3D/ParticleUniverse/CCPUParticleSystem3DTranslator.cpp @@ -165,18 +165,18 @@ void PUParticleSystem3DTranslator::translate(PUScriptCompiler* compiler, PUAbstr } } } - // else if (prop->name == token[TOKEN_PS_SCALE_VELOCITY]) - // { - // // Property: scale_velocity - // if (passValidateProperty(compiler, prop, token[TOKEN_PS_ITERATION_INTERVAL], VAL_REAL)) - // { - // Real val = 0.0f; - // if(getReal(prop->values.front(), &val)) - // { - // mSystem->setScaleVelocity(val); - // } - // } - // } + else if (prop->name == token[TOKEN_PS_SCALE_VELOCITY]) + { + // Property: scale_velocity + if (passValidateProperty(compiler, prop, token[TOKEN_PS_ITERATION_INTERVAL], VAL_REAL)) + { + float val = 0.0f; + if(getFloat(*prop->values.front(), &val)) + { + _system->setParticleSystemScaleVelocity(val); + } + } + } // else if (prop->name == token[TOKEN_PS_SCALE_TIME]) // { // // Property: scale_time diff --git a/tests/cpp-tests/Classes/Particle3DTest/Particle3DTest.cpp b/tests/cpp-tests/Classes/Particle3DTest/Particle3DTest.cpp index 7594e918e1..1cf5f6ba73 100644 --- a/tests/cpp-tests/Classes/Particle3DTest/Particle3DTest.cpp +++ b/tests/cpp-tests/Classes/Particle3DTest/Particle3DTest.cpp @@ -54,6 +54,7 @@ static std::function createFunctions[] = CL(Particle3DCanOfWormsDemo), CL(Particle3DRibbonTrailDemo), CL(Particle3DWeaponTrailDemo), + CL(Particle3DWithSprite3DDemo), }; #define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) @@ -357,22 +358,6 @@ bool Particle3DLineStreakDemo::init() if (!Particle3DTestDemo::init()) return false; - - std::string c3bfileName = "Sprite3DTest/orc.c3b"; - auto sprite = Sprite3D::create(c3bfileName); - this->addChild(sprite); - //sprite->setPosition3D(Vec3(0, -20, -25)); - //sprite->setScale(5, 5); - sprite->setRotation3D(Vec3(0, 180, 0)); - sprite->setCameraMask((unsigned short)CameraFlag::USER1); - //sprite->setOpacity(100); - auto animation = Animation3D::create(c3bfileName); - if (animation) - { - auto animate = Animate3D::create(animation); - sprite->runAction(RepeatForever::create(animate)); - } - auto rootps = PUParticleSystem3D::create("lineStreak.pu", "pu_mediapack_01.material"); rootps->setCameraMask((unsigned short)CameraFlag::USER1); rootps->setScale(5.0f); @@ -546,3 +531,42 @@ bool Particle3DWeaponTrailDemo::init() return true; } + +std::string Particle3DWithSprite3DDemo::subtitle() const +{ + return "Particle3DWithSprite3D"; +} + +bool Particle3DWithSprite3DDemo::init() +{ + if (!Particle3DTestDemo::init()) + return false; + + std::string c3bfileName = "Sprite3DTest/orc.c3b"; + auto sprite = Sprite3D::create(c3bfileName); + this->addChild(sprite); + sprite->setPosition3D(Vec3(-20.0f, 0.0f, 0.0f)); + sprite->setRotation3D(Vec3(0, 180, 0)); + sprite->setCameraMask((unsigned short)CameraFlag::USER1); + //sprite->setOpacity(100); + auto animation = Animation3D::create(c3bfileName); + if (animation) + { + auto animate = Animate3D::create(animation); + sprite->runAction(RepeatForever::create(animate)); + } + + auto billboard = BillBoard::create("Images/Icon.png"); + billboard->setPosition3D(Vec3(20.0f, 0.0f, 0.0f)); + billboard->setScale(0.2f); + billboard->setCameraMask((unsigned short)CameraFlag::USER1); + this->addChild(billboard); + + + auto rootps = PUParticleSystem3D::create("star.pu"); + rootps->setCameraMask((unsigned short)CameraFlag::USER1); + rootps->startParticleSystem(); + this->addChild(rootps, 0, PARTICLE_SYSTEM_TAG); + + return true; +} diff --git a/tests/cpp-tests/Classes/Particle3DTest/Particle3DTest.h b/tests/cpp-tests/Classes/Particle3DTest/Particle3DTest.h index fd3754b367..4c6e579d3e 100644 --- a/tests/cpp-tests/Classes/Particle3DTest/Particle3DTest.h +++ b/tests/cpp-tests/Classes/Particle3DTest/Particle3DTest.h @@ -253,6 +253,19 @@ public: virtual bool init() override; }; +class Particle3DWithSprite3DDemo : public Particle3DTestDemo +{ +public: + + CREATE_FUNC(Particle3DWithSprite3DDemo); + Particle3DWithSprite3DDemo(){}; + virtual ~Particle3DWithSprite3DDemo(){}; + + virtual std::string subtitle() const override; + + virtual bool init() override; +}; + class Particle3DTestScene : public TestScene { public: