开发者

updating iPhone view without user input

Writing a 4-player iPhone game app with pro开发者_如何学编程grammable 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


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)


how about

[myView.layer display];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜