views:

84

answers:

2

Writing a 4-player iPhone game app with programmable mix of human/autoComputer players. After each player turn the "game view" should update. I have been using "setNeedsDisplay" to update this view. However, this view updates only when my "turn processing" code is "finished" AND it awaits a human player's touch to trigger this code again.

For autoComputer players, the display updates only when it awaits the next human player's turn again. Hence, for an all autoComputer player game, the entire game is played out first (app finishes) before the setNeedsDisplay draws once - showing the final game view positions.

Is there a good way to have the autoComputer players' turns update the view once every turn at a rate such that the human players can see (e.g. once a second)?

Thanks in advance,

Steve

A: 

how about

[myView.layer display];
newacct
In general, you should never be calling `display` directly, but rather `setNeedsDisplay` (to schedule drawing by the OS).
Sixten Otto
+1  A: 

In general it would be better to run your game code on a separate thread and let the display updates take place on the main thread.

In a pinch, however, you can do this to update the display immediately after calling setNeedsDisplay:

[[NSRunLoop currentRunLoop] acceptInputForMode:NSDefaultRunLoopMode beforeDate:nil];

You have to be a bit careful with it because other queued messages can be triggered by the call as well. (On a Mac, distributed objects messages will trigger for example)

EricS
Thanks a bunch! This worked perfectly. I'll look into implementing multi-threading as well. I'm just an algorithm guy after all :-)