From 26272b2026903b4a9b8161621b05307c668c7753 Mon Sep 17 00:00:00 2001 From: minggo Date: Wed, 13 Sep 2017 15:36:11 +0800 Subject: [PATCH] use update instead of run action because Sequence has issue when work with RepeatForever (#18257) --- .../Classes/Sprite3DTest/Sprite3DTest.cpp | 42 +++++++++++-------- .../Classes/Sprite3DTest/Sprite3DTest.h | 1 + 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp index 1b27266de5..ea7b748302 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp @@ -2547,24 +2547,6 @@ Sprite3DNormalMappingTest::Sprite3DNormalMappingTest() addChild(sprite); } - float radius = 100.0; - - PointLight* light = PointLight::create(Vec3(0.0, 0.0, 0.0), Color3B(255, 255, 255), 1000); - light->runAction(RepeatForever::create(Sequence::create(CallFuncN::create([radius](Node *node){ - static float angle = 0.0; - static bool reverseDir = false; - node->setPosition3D(Vec3(radius * cos(angle), 0.0f, radius * sin(angle))); - if (reverseDir){ - angle -= 0.01f; - if (angle < 0.0) - reverseDir = false; - } - else{ - angle += 0.01f; - if (3.14159 < angle) - reverseDir = true; - } - }), nullptr))); //setup camera auto camera = Camera::createPerspective(60.0, s.width / s.height, 1.0f, 1000.f); camera->setCameraFlag(CameraFlag::USER1); @@ -2572,7 +2554,31 @@ Sprite3DNormalMappingTest::Sprite3DNormalMappingTest() camera->lookAt(Vec3(0.f, 0.f, 0.f)); addChild(camera); + PointLight* light = PointLight::create(Vec3(0.0, 0.0, 0.0), Color3B(255, 255, 255), 1000); + light->setTag(100); addChild(light); + + scheduleUpdate(); +} + +void Sprite3DNormalMappingTest::update(float dt) +{ + static float angle = 0.0f; + static bool reverseDir = false; + static float radius = 100.0f; + + auto light = static_cast(getChildByTag(100)); + light->setPosition3D(Vec3(radius * cos(angle), 0.0f, radius * sin(angle))); + if (reverseDir){ + angle -= 0.01f; + if (angle < 0.0) + reverseDir = false; + } + else{ + angle += 0.01f; + if (3.14159 < angle) + reverseDir = true; + } } Sprite3DNormalMappingTest::~Sprite3DNormalMappingTest() diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h index 3a99495432..c46a8eb036 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h @@ -591,6 +591,7 @@ public: Sprite3DNormalMappingTest(); virtual std::string title() const override; virtual std::string subtitle() const override; + virtual void update(float dt) override; virtual ~Sprite3DNormalMappingTest(); };