同步Android Canvas Surfaceview

发布于 2024-12-25 03:23:59 字数 254 浏览 4 评论 0原文

我正在开发一款 Android 画布游戏,并注意到在绘制主要游戏形式时出现了滞后现象。它是在我开始在不同部分周围撒上 synchronized(surfaceHandler) 作为尝试对抗并发数组修改之后开始的。我是否过度同步?关于何时同步、何时不同步以及何时应修改可见数据的经验法则是什么?

另外,峰值是否有可能是由其他原因引起的?绘制方法在发生这种情况时执行,但不可能进行触摸交互(大多数(如果不是全部)触摸方法是同步的)。

建议?

I am working on an android canvas game and have noticed a lagspike just as the main game form is being drawn. It started just after I started sprinkling synchronized(surfaceHandler) around different parts as an attempt to battle concurrent array modification. Did I over synchronize? What is the rule of thumb on when to synchronize and when not to, and when should visible data be modified?

Also is it possible that the spike is caused by something else? The draw method executes while this is happening, but no touch interaction is possible (most, if not all, of the touch method is synchronized).

Advice?

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

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

发布评论

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

评论(1

乖乖兔^ω^ 2025-01-01 03:23:59

我认为只要您从一个区域的表面支架生成画布,您就不必同步。这可能会也可能不会导致滞后尖峰。如果您在多个线程中使用 surfaceHandler,您可能希望将所有绘图压缩到一个线程中,否则您将需要保持同步。

I think that as long as you are generated a canvas from the surface holder in one area, you shouldn't have to synchronize. This may or may not be causing the lagspike. If you are using surfaceHandler in multiple threads, you may want to condense all your drawing into one thread or you will need to keep the synchronize.

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