Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iPhone Gameloop渲染更新来自单独的线程_Iphone_Multithreading_Game Loop - Fatal编程技术网

iPhone Gameloop渲染更新来自单独的线程

iPhone Gameloop渲染更新来自单独的线程,iphone,multithreading,game-loop,Iphone,Multithreading,Game Loop,我对iPhone开发还不熟悉。我有一个游戏循环设置如下 (void)CreateGameTick:(NSTimeInterval) in_time { [NSThread detachNewThreadSelector:@selector(GameTick) toTarget:self withObject:nil]; } 我的基本游戏勾选/渲染如下 (void)GameTick { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc

我对iPhone开发还不熟悉。我有一个游戏循环设置如下

(void)CreateGameTick:(NSTimeInterval) in_time
{
  [NSThread detachNewThreadSelector:@selector(GameTick) toTarget:self withObject:nil];
}
我的基本游戏勾选/渲染如下

(void)GameTick
{
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

  CGRect wrect = [self bounds];

  while( m_running )
  {
    [self drawRect: wrect];
  }

  [pool release];       
}
我的渲染函数被调用。但是什么也没画出来(我正在使用核心图形在派生的UIView上画一些线)

如果我通过定时器调用我的更新,那么一切都很好

你能告诉我为什么通过线程渲染失败吗?有没有可能让它通过线程工作

谢谢
Rich

您不能(当然,不应该)直接调用-drawRect:。相反,使用-setNeedsDisplay;您的视图将在下次通过事件循环更新。如果在单独的线程中运行此程序,则可能需要使用PerformSelect或OnMainThread:。

我不知道具体问题的答案,但请检查。这是一个很棒的2D游戏框架,你可以在网站上找到一些可能对你有帮助的代码示例。