【发布时间】:2009-03-06 19:12:03
【问题描述】:
我是 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];
}
我的渲染函数被调用。但是什么都没有绘制(我正在使用 Core Graphics 在派生的 UIView 上绘制一些线条)。
如果我通过计时器调用我的更新,那么一切都很好。
你能告诉我为什么通过线程完成渲染会失败吗?是否可以通过线程使其工作?
谢谢 丰富
【问题讨论】:
-
我不知道您的具体问题的答案,但请查看cocos2d-iphone。这是一个很棒的 2D 游戏框架,您可以在网站上找到一些可能对您有所帮助的代码示例。
标签: iphone multithreading game-loop