延迟后不会调用CallFunc

时间:2015-01-24 20:55:11

标签: cocos2d-x cocos2d-x-3.0

我在一个节点子类中有两个函数可以用动作做一些动画。当一个正在运行,而另一个函数被调用时,我想确保它的处理得很好。所以我做了一个测试:

Monster * node = Monster::create();
addChild(node);

auto sequence1 = Sequence::create(CallFunc::create(std::bind(&Monster:: animateWalk, node)),
                                  DelayTime::create(2.0),
                                  NULL);
// wait 2 seconds, then call this function
auto sequence2 = Sequence::create(DelayTime::create(2.0),
                                  CallFunc::create(std::bind(&Monster::animateBite, node)),
                                  NULL);

auto repeat1 = RepeatForever::create(sequence1);
auto repeat2 = RepeatForever::create(sequence2);
node->runAction(repeat1);
node->runAction(repeat2);

调用第一个函数(animateWalk),但从不调用第二个函数(animateBite)。如果我注释掉第一个runAction for repeat1,那么第二个序列就会运行。如何在第一个功能运行后延迟运行第二个功能?

1 个答案:

答案 0 :(得分:1)

 Monster * node = Monster::create();
addChild(node);

auto sequence1 = Sequence::create(CallFunc::create(std::bind(&Monster::   animateWalk, node)),
                              DelayTime::create(2.0),
                              NULL);
 // wait 2 seconds, then call this function
 auto sequence2 = Sequence::create(DelayTime::create(2.0),
                              CallFunc::create(std::bind(&Monster::animateBite, node)),
                              NULL);


// You can do something like this 

**auto FinalSeq = Sequence::create(sequence1,DelayTime::create(2.0),sequence2);

auto FinalAction = RepeatForever::create(FinalSeq);

node->runAction(FinalAction);**