简体   繁体   English

如何在游戏中使用多线程(iOS)

[英]how multithreading is used in games (iOS)

I am making a game which is based on an NSTimer calling the main loop at 40 fps, and when I run it, even on the newest iPod touch, it still lags a noticeable amount. 我正在制作一款基于NSTimer的游戏,以40 fps的速度调用主循环,当我运行它时,即使在最新的iPod touch上,它仍然会滞后一个明显的数量。 Would it be possible to use multithreading to reduce lag without reducing the framerate, or is multithreading just for keeping the ui responsive when doing complex calculations? 是否可以使用多线程来减少滞后而不降低帧速率,或者多线程是否只是为了在执行复杂计算时保持ui响应? And if it could be used, could you point me to a tutorial on how it would be implemented? 如果它可以使用,你能指点我一个如何实现它的教程吗?

In general, it's recommended that you move time-consuming operations off of the main thread. 通常,建议您从主线程中移除耗时的操作。 The main thread handles the user interface of your application, and if you block that you will prevent standard UI elements from updating and touch events from registering. 主线程处理应用程序的用户界面,如果阻止,则会阻止标准UI元素更新和触摸事件注册。 Depending on how much processing is being done behind the scenes for your game (physics, AI, etc.), you may need to move significant chunks of that to a background thread. 根据游戏幕后(物理,AI等)的处理程度,您可能需要将其中的大部分内容移动到后台线程。

Multithreading is not a simple topic, but Apple has made this a lot easier through Grand Central Dispatch, so I highly recommend reading their Concurrency Programming Guide which describes this and other techniques for achieving multithreading in your application 多线程不是一个简单的主题,但Apple通过Grand Central Dispatch使这变得更容易,因此我强烈建议阅读他们的并发编程指南 ,该指南描述了这个以及在您的应用程序中实现多线程的其他技术

Apple has an entire section entitled " Concurrency and OpenGL ES " in their OpenGL ES Programming Guide for iOS. Apple在其面向iOS的OpenGL ES编程指南中有一个名为“ Concurrency and OpenGL ES ”的整个部分。 In that, they describe several scenarios for improving performance of an OpenGL ES application using multithreading. 在此,他们描述了几种使用多线程提高OpenGL ES应用程序性能的方案。

please dont make a game which require high FPS with UIKIT. 请不要用UIKIT制作需要高FPS的游戏。 if its a 2D game you need to go for Quartz either or COCOS2D(which is OpenGL based) and if its a 3D then as @Ajeet suggested you should user OpenGL or look for 3d Engines available for iOS for high FPS. 如果它是2D游戏你需要去Quartz或者COCOS2D(基于OpenGL),如果它是3D,那么@Ajeet建议你应该使用OpenGL或者寻找适用于iOS的3D引擎以获得高FPS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM