【发布时间】:2015-01-18 23:03:31
【问题描述】:
我正在使用 Android SurfaceView 编写一个测试应用程序。我想看看它是否是一种可行的 2D 游戏开发方法。目前表现还不算太好。
似乎每 15 秒左右就会出现微小的颠簸和减速。我只在屏幕上绘制了大约 30 个矩形。我希望它能够轻松地做到这一点。
我决定分析性能。我每 10 帧记录一次平均绘制时间。我注意到的是,它有良好的绘制时间,然后它会跳起来。我确定我的代码没有在游戏循环中分配内存,所以我认为这个问题不是 GC。
我注意到性能下降了大约 100 帧,写在一个相当模棱两可的日志语句之后。有谁知道 android 正在打印的内容可能会发生什么。
每次我启动应用程序时,在这个关于删除文件的日志语句之后绘制时间都会下降......
01-18 16:53:20.221 19296-19370/com.example.scott.coloursquares I/game_screen﹕绘制时间 = 14 01-18 16:53:20.589 19296-19370/com.example.scott.coloursquares I/game_screen:绘制时间= 18 01-18 16:53:20.919 19296-19370/com.example.scott.coloursquares I/game_screen﹕绘制时间 = 13 01-18 16:53:21.250 19296-19370/com.example.scott.coloursquares I/game_screen:绘制时间= 13 01-18 16:53:21.581 19296-19370/com.example.scott.coloursquares I/game_screen﹕绘制时间 = 13 01-18 16:53:21.911 19296-19370/com.example.scott.coloursquares I/game_screen:绘制时间= 13 01-18 16:53:22.241 19296-19370/com.example.scott.coloursquares I/game_screen﹕绘制时间 = 13 01-18 16:53:22.572 19296-19370/com.example.scott.coloursquares I/game_screen:绘制时间= 13 01-18 16:53:22.906 19296-19370/com.example.scott.coloursquares I/game_screen﹕绘制时间 = 18 01-18 16:53:23.277 552-650/? D/TaskPersister:removeObsoleteFile:删除文件=5725_task.xml 01-18 16:53:23.278 552-650/? D/TaskPersister﹕removeObsoleteFile: 删除文件=5725_task_thumbnail.png 01-18 16:53:23.330 19296-19370/com.example.scott.coloursquares I/game_screen:绘制时间= 32 01-18 16:53:23.680 19296-19370/com.example.scott.coloursquares I/game_screen﹕绘制时间 = 18 01-18 16:53:24.032 19296-19370/com.example.scott.coloursquares I/game_screen:绘制时间= 20 01-18 16:53:24.399 19296-19370/com.example.scott.coloursquares I/game_screen﹕绘制时间 = 31 01-18 16:53:24.777 19296-19370/com.example.scott.coloursquares I/game_screen:绘制时间= 26 01-18 16:53:25.148 19296-19370/com.example.scott.coloursquares I/game_screen﹕绘制时间 = 23 01-18 16:53:25.473 19296-19370/com.example.scott.coloursquares I/game_screen:绘制时间= 12 01-18 16:53:25.804 19296-19370/com.example.scott.coloursquares I/game_screen﹕绘制时间 = 14 01-18 16:53:26.142 19296-19370/com.example.scott.coloursquares I/game_screen:绘制时间= 14 01-18 16:53:26.467 19296-19370/com.example.scott.coloursquares I/game_screen:draw time = 14
【问题讨论】:
-
你是如何使用 SurfaceView 的?您是使用 Canvas 还是使用 OpenGL ES 进行渲染?您使用的是设备还是模拟器? (深度背景:source.android.com/devices/graphics/architecture.html)
-
我在 Nexus 4 上运行程序。我认为 SurfaceView 不会公开 OpenGL。那就是 GLSurfaceView,它是一种完全不同的动物,如果可以的话,我想避免它。
标签: android surfaceview 2d-games