use update instead of run action because Sequence has issue when work with RepeatForever (#18257)

This commit is contained in:
minggo 2017-09-13 15:36:11 +08:00 committed by GitHub
parent c9fb0b5c03
commit 26272b2026
2 changed files with 25 additions and 18 deletions

View File

@ -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<PointLight*>(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()

View File

@ -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();
};