问题描述
随着时间的流逝,我尝试在基于图块的游戏中实现视图传呼机-刷卡很麻烦.我执行了@romangui建议的必要性能指标,发现重绘我的gaem字段大约需要48毫秒(太长的时间)-并且我已经弄平了布局,消除了过度绘制,有了我的自定义布局管理器等.
Going with the time I try to implement view pager in my tile based game - and swiping is janky. I performed necessary performance measures like suggested by @romangui , and found out that redrawing my gaem field takes about 48 msec (way too long) - and I already flattened layout, eliminated overdraw have my custom layout managers etc.
我发现在GN上绘制一个图块大约需要0.600毫秒-对于所有81个图块来说太长了.时间实际上是花在Canvas.drawBitmap(...)
I discovered that drawing one tile on GN takes about 0.600 msec - way too long for all 81 tiles. Time is actually spend on Canvas.drawBitmap(...)
任何想法如何提高性能?我只有6种不同的位图,它们只能加载一次并重新使用. ARGB_8888.当然,它们不必与实际显示的大小相匹配.
Any ideas how to improve performance? I have only 6 different bitmaps, they are loaded once and reused. ARGB_8888. Of course they to not necessarilly match actual displayed size.
如果在对布局进行测量后将其预渲染为实际的显示尺寸,我会得到更好的性能吗?
Would I get better performance if I pre render them for actual display size after my layout was measured?
还是我该咬一下子弹并用游戏状态预先渲染一个大的位图,以用于滚动?
Or shall I bite the bullet and pre render one big bitmap with my game state just for scrolling?
推荐答案
您应确保不要让Android在绘图时使用图像缩放.
You should be sure that you do not make Android to use scaling of the images while drawing.
尝试使用以前缩放的图像,如在地图上绘制缩放的位图画布?
Try to use previously scaled images, as in Draw a scaled bitmap to the canvas?
这篇关于在Android上提高Canvas.drawBitmap()的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!