NSTimers VS NSThreading
我正在开发一款 iPhone 游戏,玩家通过倾斜 iPhone 来让角色移动,但不幸的是,我用来制作场景动画的所有计时器都会减慢我的游戏速度。有人告诉我使用 NSThreads,但我真的对它们一无所知。我的问题是,使用 NSThreads 和 NSTimers 有什么区别?或者说使用NSThreads有什么好处?它们有什么用?
I'm working on an iPhone Game where the player tilts the iPhone to make the character move, but unfortunately all of the timers I'm using to animate the scenario are slowing down my game. I've been told to use NSThreads, but I really don't know anything about them. My question is, What are the differences between using NSThreads and NSTimers? Or what are the advantages of using NSThreads? How are they useful?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
计时器用于异步而不是并发执行代码。
线程用于并发执行代码。
另请参阅:
Timers are used for asynchronous, not concurrent, execution of code.
Threads are for concurrent execution of code.
See also:
计时器是稍后简单地调用方法的对象。线程是要处理的附加“流”,处于伪并行状态。这就像比较苹果和橙子——它们并没有真正的相关性。我能看到的唯一关系是,如果你想在后台进行一些处理,但你不应该在后台线程中进行 UI 调用,为什么你要使用计时器来让你的角色移动?知道了这一点,我们也许能够提供替代解决方案。
Timers are objects that simply call methods at a later time. Threads are additional "streams" of stuff to be processed, in psuedo-parallel. It's like comparing apples to oranges—they're not really related. The only relation I can see is if you want to do some processing in the background, but you shouldn't be doing UI calls in background threads, Why are you using timers to make your character move? Knowing that, we might be able to supply an alternate solution.