安卓:2D。 OpenGL 还是 android.graphics?

发布于 2024-08-31 05:41:11 字数 410 浏览 2 评论 0原文

我正在和我的朋友一起开发我们的第一个 Android 游戏。基本思想是,游戏的每一帧整个表面都分两步重新绘制(1 个大位图):

  1. 带有一些静态图像 (PNG) 的背景擦除前一帧
  2. 然后撒满大量粒子,从而产生以下效果肥皂泡,其中有大约 20 个位图的池,随机挑选这些位图以产生所有气泡(200 - 300 之间)都不同的错觉。每帧更新气泡位置(约 50 毫秒),产生移动气泡的效果。

数学引擎采用 C (JNI) 语言,目前所有绘图都是使用 android.graphics 包完成,与 Lunar Lander 非常相似(因为这是我使用的示例)。 它可以工作,但动画有点生涩,我可以通过手机的温度感觉到它非常繁忙。我们会从切换到 OpenGL 中受益吗?作为一个额外的问题:优化我们现在拥有的绘图机制(例如月球着陆器)的好方法是什么?

I'm working with my friend on our first Android game. Basic idea is that every frame of the game the whole surface is redrawn (1 large bitmap) in 2 steps:

  1. Background with some static image (PNG) wipes out previous frame
  2. Then it is sprinkled all over with large number of particles which produces effect of soapy bubbles where there's a pool of about 20 bitmaps which randomly gets picked to produce illusion that all bubbles (between 200 - 300) are all different. Bubbles positions updated on each frame (~50ms) producing effect of moving bubbles.

The math engine is in C (JNI) and currently all drawing is done using android.graphics package very similar (since that was the example I was using) to Lunar Lander.
It works but animation is somewhat jerky and I can feel by temperature of my phone that it is very busy. Will we benefit from switching to OpenGL? And as a bonus question: what would be a good way to optimize the drawing mechanism (Lunar Lander like) we have now?

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

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

发布评论

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

评论(2

十秒萌定你 2024-09-07 05:41:11

现在我开始使用 OpenGL ES,我还将它用于 2D 图形。这种方式是最灵活的,而且速度极快(看看 这个示例代码。它是关于 2D 渲染的,您可以从中看到 OpenGL 的强大功能。

这并不是最容易开始的事情,但是有一些很好的教程 - 例如,这个是一个非常好的。

Now I've started to work with OpenGL ES, I would also use it for 2D graphics. This way is the most flexible and it's extremely fast (look at this example code. It's about 2D rendering, and there you can see the power of OpenGL.

It's not the easiest thing to start with, but there are some good tutorials out there - for example, this is a very good one.

芸娘子的小脾气 2024-09-07 05:41:11

不要每次都重新绘制整个屏幕。这就是导致帧率低的原因。使用invalidate方法来标记每帧发生变化的区域。

Don't redraw the entire screen each time. That's what causes your low framerate. Use the invalidate method to mark the areas that have changed each frame.

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