是什么导致帧率下降?

发布于 2024-07-25 15:44:01 字数 262 浏览 2 评论 0原文

我正在用 cocos2d 编写一个游戏,我注意到帧速率随着游戏的进行而下降。 我已经检查了是否有泄漏,但一切看起来都很好,所以我不知道下一步该怎么做。 抱歉,如果这是一个非常基本的问题,那么哪些因素会导致帧速率损失?

当我从图层中清除精灵时,问题似乎变得更糟。 有时帧速率会跳回到 60,但偶尔会下降到 30 或更低,并且永远不会恢复。 几分钟后,动画明显变慢,游戏几乎停止。 我不确定这是否是 cocos2d 特有的问题还是游戏开发中的常见问题,但它会使游戏无法玩:(

I'm writing a game with cocos2d and I have noticed that the frame rate drops as the game progresses. I've checked for leaks but everything looks fine so I'm at a loss as to what to do next. Sorry if this is a really basic question but what sort of factors cause frame rate loss?

The problem seems to get worse when I clear the sprites from a layer. Sometimes the framerate jumps back to 60 but occasionally it drops down to 30 or lower and never recovers. After a few minutes the animations are noticably slower and the game pretty much grinds to a halt. I'm not sure if this is specific to cocos2d or a common issue in game development, but it renders the game unplayable :(

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

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

发布评论

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

评论(4

妞丶爷亲个 2024-08-01 15:44:01

您如何测试内存泄漏? 我认为你不应该排除这个原因,直到你完全确定,因为这听起来像经典的“内存泄漏行为”。

还要确保你没有像日志或内存中的东西在每一帧中不断变得越来越大(我这么说是因为这过去发生在我身上)。

还要确保您不会随着游戏的进行而不断加载新的对象和/或精灵。 尝试将所有加载调用保留在逻辑的初始化段中。

How are you testing for memory leaks? I don't think you should rule that out as the cause until you are absolutely certain because that sounds like classic "memory leak behaviour".

Also make sure you don't have something like a log or something in memory which is continually getting larger and larger every frame (I say so because that's happened to me in the past).

Also make sure you aren't continually loading new objects and/or sprites as your game progresses. Try and keep all your load calls in the initialization segment of your logic.

洒一地阳光 2024-08-01 15:44:01

显然,如果您添加更多精灵,您的帧速率将会下降,因为它有更多需要处理的内容。

现在,我对 cocos2d 一无所知,但是当您“从图层中清除精灵”时,听起来除了存储它们现在被隐藏的事实之外,它还只是将它们隐藏在视图之外。

也许尝试使用更少的精灵?

Your framerate will drop if you add more sprites, obviously, because it has more to process.

Now, I do not know anything about cocos2d, but when you are "clearing the sprites from a layer", it sounds as though it simply hides them from view in addition to storing the fact that they are now hidden.

Maybe try and use fewer sprites?

━╋う一瞬間旳綻放 2024-08-01 15:44:01

您是否重复使用预加载的纹理? 如果你不是,你应该这样做。 一次又一次加载相同的纹理既慢又容易泄漏。

此外,您是否会发布已经完成的纹理? 即使精灵消失了,纹理仍然存在。

Are you reusing preloaded textures? If you aren't you should. Loading the same texture again and again is both slow, and is a leak.

Additionally, are you releasing textures you're done with? Even though the sprite is gone the texture is still there.

绝影如岚 2024-08-01 15:44:01

我最近遇到了 Flash 的一个问题,涉及图形光栅化逐渐变慢,所以也许这里可能会发生类似的情况。 当系统必须执行太多工作时,通常会出现速度减慢的情况。 内存泄漏是显而易见的,因为内存的过度分配和碎片从来都不是好事,但请考虑一下:

我发现我忘记在 Graphics 对象上调用“clear”,所以每次我重新绘制精灵的边框时,正在绘制另一个圆角矩形,并且绘制命令是累积的。 经过几十次交互后,它在自身上绘制了这个填充的圆角矩形一百次。 着色器、代码等只占用了不到 1% 的渲染时间,但过度光栅化却影响了我的帧速率。

因此,我建议检查对象创建、忘记清除对象、绘制方法等内容。确保系统没有做不必要的工作或积累不必要的操作,而不仅仅是内存对象。

I recently ran into a problem with Flash involving a progressive slowdown in graphics rasterization, so perhaps something similar could be happening here. A slowdown will generally occur when the system has to perform too much work. Memory leaks are obvious, because over-allocation and fragmentation of memory are never good, but consider this:

What I discovered was I had forgotton to call "clear" on the Graphics object, so every time I redrew the border of a sprite, it was drawing another rounded rectangle and the draw commands are cumulative. After a few dozen interactions, it was drawing this filled, rounded rectangle a hundred times over itself. The shaders, code, etc. were all taking up less than 1% of the rendering time, but that over-rasterization was killing my framerate.

So I would suggest checking for things like object creation, forgetting to clear things, drawing methods, etc. Make sure the system is not doing unnecessary work or accumulating unnecessary operations, not just memory objects.

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