Mac Dev - 如何刷新 2d 游戏的视图?

发布于 2024-08-11 06:03:16 字数 342 浏览 3 评论 0原文

如果您看到我的其他问题,您就会知道我开始尝试在 Mac 上制作简单的 2D 游戏。在那里我决定使用哪个库(OpenGL 或 Quartz),但无论如何我都必须使用 Cocoa 来使其成为一个漂亮的 Mac 应用程序,以及窗口和视图(使用 OpenGL、NSOpenGLView)。显然,对于游戏来说,视图每秒必须重绘多次。要进行视图重绘,您需要执行[view setNeedsDisplay:YES];,但我读到您不应该多次执行此操作(因为它的成本很高)。但是我应该如何重绘视图,例如以合理的 fps 进行 2d 游戏?谢谢。

If you see my other question, you'll know that I'm starting to try making simple 2d games on mac. There I was deciding which library to use (OpenGL or Quartz), but no matter what I'll have to use Cocoa to make it a nice Mac application, and for the window and the view (with OpenGL, NSOpenGLView). Obviously for a game, the view will have to redraw many times per second. To make a view redraw, you need to do [view setNeedsDisplay:YES];, but I read that you shouldn't do this many times (because it costs a lot). But how am I supposed to redraw the view e.g. at a reasonable fps for a 2d game? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遗心遗梦遗幸福 2024-08-18 06:03:16

“只有在必要时才重画”的规则并不真正适用于游戏。游戏通常会尝试以显示器的刷新率或尽可能接近该刷新率来重绘。

本页介绍了如何在cocoa中进行OpenGL渲染循环: http:// /developer.apple.com/mac/library/qa/qa2004/qa1385.html

The "only redraw if you have to" rule doesn't really apply to games. Games usually try to redraw at the refresh rate of the monitor, or as close to that rate as possible.

This page describes how to make on OpenGL rendering loop in cocoa: http://developer.apple.com/mac/library/qa/qa2004/qa1385.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文