According to the documentation, runBlock runs immediately, and the duration of moveTo not respected. Sequencing of both code A and code B is correct, but in the latter case it seems that it does not match the sequence, since the duration of moveTo() not respected.
As a solution to the problem of starting a code block that leads to one or more actions, observing the duration, try this code:
func notSoBadMoveAction() -> SKAction { let realDest = CGPointMake(itemA.position.x, itemA.position.y) let moveAction = SKAction.moveTo(realDest, duration: 2.0) return moveAction } itemB.runAction(SKAction.sequence([ SKAction.waitForDuration(0.5), notSoBadMoveAction(), SKAction.runBlock { itemB.removeFromParent() }]))
This code uses the full duration to move, and it can replace some (but maybe not all others) other uses of runBlock. If you want, the function can also take parameters and, as such, be turned into an even more general case of generating actions.
ADDITIONAL: The following is an alternative version of the function that displays the possibilities of adding actions and calculating the elements inside the function:
func myMoveAction(pos: CGPoint, duration : NSTimeInterval) -> SKAction { let realDest = CGPointMake(pos.x, pos.y) let moveAction = SKAction.moveTo(realDest, duration: duration/4) let moveAction2 = SKAction.moveTo(CGPointMake(realDest.x/2, realDest.y/2), duration: duration * 2/4) let moveAction3 = SKAction.moveTo(realDest, duration: duration/4) return SKAction.sequence([moveAction, moveAction2, moveAction3]) }
source share