首页 > 解决方案 > Cocos2d-x 4.0 Lens3D 和 Waves3D 动画

问题描述

我使用下面的代码为背景图像制作像水一样的动画

    auto background = Sprite::create(TEX_MM_BG);
    background->setPosition(Vec2(SW*0.5f, SH*0.5f));

    auto nodeGrid = NodeGrid::create();
    nodeGrid->addChild(background);
    this->addChild(nodeGrid, 0);


    ActionInterval* lens = Lens3D::create(10, Size(32, 24), Vec2(100, 180), 150);
    ActionInterval* waves = Waves3D::create(10, Size(15, 10), 18, 15);

    nodeGrid->runAction(RepeatForever::create(Sequence::create(waves,lens, NULL)));

动画效果不错。但它停止 10 秒然后播放 10 秒然后再次停止 10 秒......它重复。如何避免中途停车?

标签: c++iosiphonexcodecocos2d-x

解决方案


它并没有停止应用波浪效果,然后是镜头效果。在应用镜头效果时,波浪的动画会停止。

正确的编码方式是使用 Spawn:

 ActionInterval* lens = Lens3D::create(10, Size(32, 24), Vec2(100, 180), 150);
 ActionInterval* waves = Waves3D::create(10, Size(15, 10), 18, 15);
 // Spawn will run both effects at the same time.
 auto lensWaveSpawn = Spawn::createWithTwoActions(lens, waves);

 auto seq = Sequence::create(lensWaveSpawn, nullptr);
 nodeGrid->runAction(RepeatForever::create(seq));

推荐阅读