Android的drawBitmap性能对于许多位图? [英] Android drawBitmap Performance For Lots of Bitmaps?

查看:783
本文介绍了Android的drawBitmap性能对于许多位图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个Android游戏的过程中,我似乎有与绘图画布性能问题。我的游戏中有多个级别,并且每个人都有(显然)不同的号码它的对象。

I'm in the process of writing an Android game and I seem to be having performance issues with drawing to the Canvas. My game has multiple levels, and each has (obviously) a different number of objects in it.

但奇怪的是,在一个层面上,其中包含45的图像,完美运行(近60 FPS)。然而,另一个层面,其中包含81的图像,勉强运行在所有(11 fps)的;这是pretty的多少无法播放。这看起来奇怪的人除了我之外?

The strange thing is that in one level, which contains 45 images, runs flawlessly (almost 60 fps). However, another level, which contains 81 images, barely runs at all (11 fps); it is pretty much unplayable. Does this seem odd to anybody besides me?

所有我使用被png格式的和上述水平之间的唯一差别图像是图像的数量。

All of the images that I use are .png's and the only difference between the aforementioned levels is the number of images.

这是怎么回事呢?可以在画布根本画不出这么多的图片的每个游戏循环?如何将你们建议我提高这样的表现?

What's going on here? Can the Canvas simply not draw this many images each game loop? How would you guys recommend that I improve this performance?

在此先感谢。

推荐答案

觉得奇怪,我也是如此。我也开发游戏,很多层次的,我可以很容易地对屏幕100游戏对象,还没有看到类似的问题。

Seems strange to me as well. I am also developing a game, lots of levels, I can easily have a 100 game objects on screen, have not seen a similar problem.

如果使用得当,drawbitmap应该是非常快的真心;它比一个复制命令而已。我甚至不画圈圈本身;我有pre-呈现圆位图。

Used properly, drawbitmap should be very fast indeed; it is little more than a copy command. I don't even draw circles natively; I have Bitmaps of pre-rendered circles.

然而,位图在Android上的表现是你如何做到这一点非常敏感。创建位图可以是非常昂贵的,因为Android的默认可以自动规模是CPU密集型的PNG图像。所有这些东西需要做的只有一次,你的渲染循环之外。

However, the performance of Bitmaps in Android is very sensitive to how you do it. Creating Bitmaps can be very expensive, as Android can by default auto-scale the pngs which is CPU intensive. All this stuff needs to be done exactly once, outside of your rendering loop.

我怀疑你是找错了地方。如果创建并使用相同的各种图像在同样类型的方式,则倍增屏幕图像的数量不应超过4个氨基酸因子降低性能在最应该是线性的(2倍)。

I suspect that you are looking in the wrong place. If you create and use the same sorts of images in the same sorts of ways, then doubling the number of screen images should not reduce performance by a a factor of over 4. At most it should be linear (a factor of 2).

我的第一个怀疑的是,大部分的CPU时间的碰撞检测。不同于绘制的位图,这通常上升为互动对象数量的平方,因为每个对象都有反对所有其他物体碰撞测试。您加倍游戏对象的数量,但你的性能下降到一个季度,即根据对象的数目的平方。如果是这样的话,不要绝望;有做碰撞检测不成长为对象的数目的平方的方法

My first suspicion would be that most of your CPU time is spent in collision detection. Unlike drawing bitmaps, this usually goes up as the square of the number of interacting objects, because every object has to be tested for collision against every other object. You doubled the number of game objects but your performance went down to a quarter, ie according to the square of the number of objects. If this is the case, don't despair; there are ways of doing collision detection which do not grow as the square of the number of objects.

在此同时,我会做基本的测试。如果你不实际绘制一半的对象,会发生什么?请问游戏运行得更快?如果不是,它无关,与图纸。

In the mean time, I would do basic testing. What happens if you don't actually draw half the objects? Does the game run much faster? If not, its nothing to do with drawing.

这篇关于Android的drawBitmap性能对于许多位图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆