Normally one never wants to block the main thread, but I cannot figure how to manage multiple Spritekit animations.
example :
if !abort {
swap_tiles(tile1,tile2) // execute players move
abort = processBoard()
if abort { swap_tiles(tile1,tile2) } // if not valid, restore tiles to original location
}
swap_tiles performs an animation… works just fine… HOWEVER it has a duration of 0.5 seconds
the function processBoard() takes less than that… And it either returns TRUE rather quickly in the case of an “invalid move”, or may take another fraction of a second (where it then fires off MORE animations)
So in the case for example where abort returns TRUE. the 2nd swap tiles begins BEFORE the first one has completed… where it is false, there could be up to 50 animations in progress, and some of THOSE also need to complete before the next set fires.
If I could block the main thread until each animation completed, then the problem would be solved (note the block wold be <1 second I’m guessing)
Right now, all the animations run, but because the end up concurrent, the information some animations need isn’t there, because a previous animation is still in progress.
Using completion closures doesn’t seem to work, since there is a lot of logic between firing an animation, the logic decides what if any to fire, and what parameters are involed…