将一个主 UIView 拆分为多个 UIView 以进行 Sprite 绘制 (Quartz 2d)

发布于 2024-09-27 03:21:46 字数 273 浏览 1 评论 0原文

我目前有一款游戏,它使用一个 UIView 在每次游戏时通过其 drawrect 方法在屏幕上绘制多个精灵。有人建议我,为了提高性能,最好将每个精灵分离到它自己的 UIView 中。

我的问题是:

  • 从结构上讲,这是如何运作的?我是否创建一个 UIView,然后添加更多 UIView 作为子视图?
  • 游戏控制器是否应该调用一个 UIView,然后该 UIView 调用下一个?或者它应该返回到游戏控制器。

预先非常感谢,

马丁

I currently have a game which uses one single UIView to draw a number of sprites onto the screen in its drawrect method every game tic. I have been advised that for performance it would be better to separate out each sprite into it's own UIView.

My questions are :

  • Structurally how does this work ? Do I create one UIView and then add further UIViews as a subview ?
  • Should the gamecontroller call one UIView and then that UIView call the next ? Or should it return to the game controller.

Many thanks in advance,

Martin

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

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

发布评论

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

评论(1

初心 2024-10-04 03:21:46

如果您要创建一堆单独的容器,您可能需要考虑使用 CALayers 而不是 UIViews,它们对于核心动画操作等来说会更快。

如果您使用 UIViews,您将有一个父视图,然后将其他视图添加为子视图,如果您使用 CALayers,您会将图层作为子图层添加到主 view.layer。

You might want to consider using CALayers instead of UIViews if you are going to create a bunch of separate containers, they will be faster for core animation operations etc.

If you use UIViews you would have one parent view then add your others as subviews to that, if you use CALayers you would add your layers as sublayers to the main view.layer.

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