Continuing the discussion from How can I delay game/code during an action? :
I am writing a checkers program. There is no need for a scheduler (no need to continuously keep time), but after some actions I want a delay. After the player moves I want a delay before the AI moves. If a piece can possibly double jump, I need to set a delay between when the first jump happens, and the second jump can occur, as the piece moves over time with animation.
For example: I have this code below that calls the move function.
if (move(currpiece, pos) == true)
{
//**I WANT TO PAUSE HERE
// now opponent moves
Position place;
GameBoard::piece* pp;
place = Game->getOppMove(pp);
while (move(pp,place) == false); //**ALSO NEED TO PAUSE HERE
}
The move function uses a Cocos action::
Action* moveToTargetPosition = MoveTo::create(piece_move_speed, posToLoc(pos));
sprite->runAction(moveToTargetPosition);
return Game->move(pce,pos);
in this example, I want to pause before the opponent piece moves. Also, if the AI can double jump, then the while loop calls two move functions with the same sprite (the second move function is called before the first action is finished), and there is an error.
How do I go about adding delaying my code until the move action is complete?
Thank you
I have code something like this.
I have to move a sprite to particular position and after completion of that action, i want to remove it.
But it is removing it without performing the action. How, to achieve this.
sp is a Sprite
sp->runAction(MoveTo::create(1.0, Vec2(visibleSize.width/2, visibleSize.height/2)));
this->removeChild(sp);
In this case you can simply create sequence. Sth like:
auto seq = Sequence::create(MoveTo::create(1.0f, Vec2(x,y)), RemoveSelf::create(), nullptr);
sp->runAction(seq);