void BDFunctions::onAnimatePlayedCard(BDCardBean* bdCardBean) {
cocos2d::CallFunc::create(std::bind(&BDFunctions::onPathFinished, this, bdCardBean));
auto callback = cocos2d::CallFunc::create(std::bind(&BDFunctions::onPathFinished, this, bdCardBean));
auto moveTo = cocos2d::MoveTo::create(0.2f, cocos2d::Vec2(BDShared::getInstance()->TABLE_CARD_X, BDShared::getInstance()->TABLE_CARD_Y));
auto seq = cocos2d::Sequence::create(moveTo, callback, nullptr);
bdCardBean->getAnimatedSprite()->runAction(seq);
}
and this method is called inside a loop as:
for (BDCardBean* bdCardBean : bdPlayer->getCards()) {
onAnimatePlayedCard(bdCardBean, bdPlayer);
}
But on executing this code, it seems the callback “onPathFinished” called once at the end, I don’t know what is the problem, and If somehow to join “onPathFinished” with “onAnimatePlayedCard” as one method, finishing onAnimatePlayedCard after onPathFinished,
My real problem is on Multithreading, I use gpg for RealTimeMultiplayer, but this piece of code reproduce it,
In the above line, you are not storing the instance of the CallFunc, hence you are not doing anything to it, it will be removed in the next update call.
For this sequence, you are calling moveTo at first then you are calling your callback
so, obviously your callback actions will be called at the end for once.
There’s nothing wrong with multi-threading anywhere.
You haven’t laid the code properly I believe, please cross-check once.
Thank you for your response, I completely agree with you,
Just one thing if you can, how to store the instance of the CallFunc, to be used for each action,