我在網上討論了在可可中創建遊戲循環的問題。我見過的大部分遊戲循環都使用NSTimer每隔60秒觸發一次事件。爲什麼似乎沒有使用Grand Central Dispatch的示例,就像下面的Apple開發人員文檔的源代碼一樣。有沒有我不知道的問題?爲什麼可可遊戲避免Grand Central Dispatch創建計時器?
dispatch_source_t CreateDispatchTimer(uint64_t interval,
uint64_t leeway,
dispatch_queue_t queue,
dispatch_block_t block)
{
dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER,
0, 0, queue);
if (timer)
{
dispatch_source_set_timer(timer, dispatch_walltime(NULL, 0), interval, leeway);
dispatch_source_set_event_handler(timer, block);
dispatch_resume(timer);
}
return timer;
}
也許是因爲NSTimer比GCD更有名,比GCD更可怕,因爲GCD只是MacOS10.6.x/iOS4.x及更高版本? – nacho4d 2011-02-13 08:01:03