Slowing Things Down

I have been working on the AI for my Game.  It was going well until the end.  When the AI had its go the animations (same as for the player) all waited until the end of the AI's turn and only some of it displayed (the last bit).

The AI turn is kicked off by the player hitting his/her end of turn via begintouches.  Mmmm.  It seemed that the animations weren't kicking off until the touches event finished processing (i.e. the whole AI turn).  So I tried using Multiple threads and timers to move the animation off to thread.  But this was very messy and didn't seem to be it anyway.  

I tried putting 

[NSThread sleepForTimeInterval:1.0]; 

"to sleep" in but that just put the thread to sleep and just delayed the problem.  Not fixing it.

I was starting to think I had done something fundamentally wrong and as I am new to Objective-C and iPhone this was a distinct possibility.

Lots of searching later I hit this post which advised to use 

[[NSRunLoop currentRunLooprunUntilDate: [NSDate dateWithTimeIntervalSinceNow2.0f] ];

which seems to stop new commands from running for a fixed time but lets the background processing (i.e. the animation time to catch up).  So I put a few NSRUNLoop commands around whenever I needed a bit of a delay in processing to allow the animations to catchup.

Bingo, perfect.  Not sure if this is the best way to do it (overall) but it works and that is the important thing at the moment.  

Copyright 2010-11 Clockworkapps