简体   繁体   English

Android游戏中的表现

[英]Performance in Android Game

I coded a game for android. 我为Android编写了一个游戏。 For each frame I use the same procedure. 对于每个帧我使用相同的过程。

So my game runs smooth, but in some moments the game get stuck. 所以我的游戏运行顺畅,但在某些时刻游戏卡住了。 I searched with deltaTimes in the methods, but it is not easy to find the problem. 我在方法中使用deltaTimes进行了搜索,但是找不到问题并不容易。

In the picture for the deltaTime between the frames: 在图片中,帧之间的deltaTime: 帧时间 you can see the peaks. 你可以看到山峰。 Between the peaks the game runs smoothly. 在高峰之间游戏顺利进行。

So my question for you is, do you know a profiler or some similar in eclipse to find the reason for the peaks? 所以我的问题是,你知道一个探测器或类似的日食以找到峰值的原因吗? Or do you know a website with performance tipps for game development in android? 或者你知道一个网站有Android的游戏开发性能tipps?
The garbage collector isn't it, because in the debug console the message does not come. 垃圾收集器不是它,因为在调试控制台中消息不会出现。

//EDIT 1: After searching for more performance tipps i added a custom theme class: //编辑1:在搜索更多性能tipps后,我添加了一个自定义主题类:

<resources>
    <style name="Theme.NoBackground" parent="android:Theme">
        <item name="android:windowBackground">@null</item>
    </style>
</resources>

This gave me a better performance, but there a still high peaks. 这给了我更好的表现,但仍有很高的峰值。 第二次性能测试

One of the biggest reasons for these types of spikes are when garbage collection kicks in. Frames stop an slow if you have say an arraylist of bubbles, and each bubble contains an image , you'd use a pooling system to reuse the bubbles rather than letting the garbage collector collect, which would cause these spikes. 这些类型的峰值的最大原因之一是当垃圾收集开始时。如果你说一个气泡的arraylist,并且每个气泡包含一个图像,你会使用一个池系统来重复使用气泡而不是让垃圾收集器收集,这将导致这些尖峰。

Garbage collection should be avoided while your game is running and the assets should be loaded on the start of the game. 在游戏运行时应避免垃圾收集,并且应在游戏开始时加载资源。

Some articles here that may be of use to you.. 这里的一些文章可能对你有用..

Avoid using the enhanced for-loop for ArrayLists in Android games 避免在Android游戏中使用针对ArrayLists的增强型for循环

Object pooling for android gaming 用于Android游戏的对象池

You can use traceview to see where do you spend your time. 您可以使用traceview查看您在哪里花费时间。
Profiling with traceview 使用traceview进行性能分析

And there are some best practices provided by Android in order to improve the performance of an app. Android提供了一些最佳实践,以提高应用程序的性能。
Performance Tips 性能提示

It definitely seems like garbage collection. 它看起来像垃圾收集。 To verify this, you can filter for logcat messages starting with "GC_" while running the game. 要验证这一点,您可以在运行游戏时过滤以“GC_”开头的logcat消息。

Others already posted tips for fixing that, here's what I'd add: look at every line containing the new() operator, and think about where the instance created will eventually end its lifetime. 其他人已经发布了修复的提示,这是我要添加的内容:查看包含new()运算符的每一行,并考虑实例创建的最终位置。 If it's during the game, it should be changed. 如果是在比赛期间,则应该进行更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM