Hello,
I have a class that inherits from Sprite, this class has a function that is running everytime to simulate automovement. This is more or less the class I have right now:
myClass::myClass()
{
initWithSpriteFrameName("ball_01.png");
this->makeRandomMovement();
}
void myClass::moveLeft(){
// ... ... ... prepare animations
auto cb = CallFunc::create( [this]() {
this->makeRandomMovement();
});
auto seq = Sequence::create(other_animations, cb, nullptr);
this->runAction(seq);
}
void myClass::jumpTwice(){
auto jump = JumpBy::create(1.0, Vec2(0, 0), 40, 1);
auto cb = CallFunc::create( [this]() {
this->makeRandomMovement();
});
auto seq = Sequence::create(jump, cb, nullptr);
this->runAction(seq);
}
void myClass::makeRandomMovement()
{
int random_int = rand() % 7;
switch ( random_int ) {
case 0:
moveLeft();
break;
default:
jumpTwice();
break;
}
}
void myClass::jumpToPosition(cocos2d::Vec2 position){
this->unscheduleAllCallbacks();
// I tried this but it breaks the code flow
while (this->getNumberOfRunningActions() > 0){
std::cout << this->getNumberOfRunningActions() << std::endl;
std::cout << "Waiting active action to finish" << std::endl;
}
}
I cannot find a way to:
- Capture the current running sequence
- Wait to finish the current animation
- Stop the next callback
- Do a different animation and then add the callback to makeRandomMovement()
Maybe I’m losing the way to do something like this, any help will be appreciated