开发者

A method to override that gets called a couple of times a second? or a loop its safe to code into?

Making a simple card game, and it it should ok when the user is in control since he will push a button. It will call my method assigned to that button and logic will be performed and screen updated.

But when the players turn ends, and i want the AI to run everything for a few seconds, update the screen with its decisions etc. Handle some logic, call some animation before handing the control back to the user.

Is there a method i can override in my Controller class that开发者_如何学C which is a subclass of NSObject that gets called every loop or at least 5-10times a second? Or how is it you guys handle this?

Thanks -Code


It doesn't seem like you want a background thread at all (at least not one you make) or a timer.

What you really want to to is visually animate the AI actions, to that end look at the CoreAnimation stuff, to define animations for AI actions and then play them. You can specify a time period an animation is to take.

Look at this project for examples of animation from the simple to the complex:

http://github.com/neror/CA360


Just create a an NSTimer that calls a tick method at whatever frequency you desire. But keep in mind that NSTimer is not guaranteed to be precise, so in order to avoid gradually accumulating errors, you might want to check how much time has actually passed (e.g. if the timer fires an average of 10 ms late over 500 ticks, code that depends on precise timing will be five seconds off).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜