随着时间的推移,一个影片剪辑的帧速率会慢慢下降。什么可能导致这种情况? [闪光CS3]

发布于 2024-08-28 07:41:07 字数 720 浏览 4 评论 0原文

我正在创建一个 Flash 节奏游戏。我有一个循环(在某个帧我有一个 gotoAndPlay)影片剪辑,其中包含滚动的音符,循环大约三分钟。随着关卡的进展,影片剪辑的帧速率开始滞后并出现卡顿。就影片剪辑而言,没有调用任何变量或函数来导致这种情况。我不知道这是怎么发生的。还值得一提的是,注释是由文本(非光栅化文本)表示的,如果这有什么区别的话。就发布我的代码而言,我认为它太复杂了,不值得您花时间。我只是不明白这个影片剪辑的帧速率如何独立于游戏的其余部分而下降。

编辑:按照 Sam 的建议,我发现了导致游戏速度减慢的代码块。

if(_noteBar._decide)
        {
            if(_noteBar._correctHits == _noteBar._correctNumberHits)
            {
                _noteBar._totalCorrect = true;
            }

            else if(_noteBar._correctHits > 0) {}

            else
            {
                _noteBar._decrement = true;
            }
        }

这段代码运行每一帧。老实说,我不明白这怎么会降低帧率这么多。我只是检查并分配一些变量。此外,这对于我的游戏的运行非常重要。难道我正在检查来自不同类的变量吗?

I'm creating a flash rhythm game. I have a looping (at a certain frame I have a gotoAndPlay) movieclip that contains the notes that scroll by, which loops for about three minutes. As the level progresses, the movieclip's framerate begins to lag and stutter. As far as the movieclip is concerned, no variables or functions are being called that would cause this. I have no idea how this could occur. It is also worth mentioning that the notes are represented by text (non-rasterized text), if that makes any difference. As far as posting my code goes, I think it would be far too convoluted to be worth your time. I just don't understand how the framerate of this movieclip could drop independent of the rest of the game.

EDIT: Following Sam's advice, I found the chunk of code that is slowing down my game.

if(_noteBar._decide)
        {
            if(_noteBar._correctHits == _noteBar._correctNumberHits)
            {
                _noteBar._totalCorrect = true;
            }

            else if(_noteBar._correctHits > 0) {}

            else
            {
                _noteBar._decrement = true;
            }
        }

This chunk of code runs every frame. I honestly don't understand how this could bring down the framerate so much. I'm just checking and assigning some variables. Also, this is pretty much crucial to the functioning of my game. Could it be that I'm checking variables from a different class?

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

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

发布评论

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

评论(2

溺ぐ爱和你が 2024-09-04 07:41:07

尝试尽可能多地删除代码(将其注释掉),然后慢慢将其添加回来,直到找到导致速度减慢的位置。

Try removing your code as much as possible (commenting it out) and then slowly add it back in until you find the spot that is causing the slowdown.

姐不稀罕 2024-09-04 07:41:07

该代码看起来肯定不会导致速度变慢。每帧运行多少次?您应该在退出 if 之前设置 _noteBar._decide = false 吗?您可以添加额外的检查以确保它每帧只运行一次吗?在 Flex 中,这是通过 invalidateProperties/commitProperties 完成的,但我不知道 Flash 中的等效项。

代码可以稍微优化一下,但我怀疑这会产生影响。

var noteBar = _noteBar;

if(noteBar._decide)
{
    va correctHits = noteBar._correctHits;
    if(correctHits == _noteBar._correctNumberHits)
    {
        _noteBar._totalCorrect = true;
    }
    else if(correctHits > 0) 
    {
    }
    else
    {
        noteBar._decrement = true;
    }
}

That code certainly doesn't look like it could cause a slowdown. How many times is it being run per frame? Should you be setting _noteBar._decide = false before you exit the if? Can you add an extra check to make sure it only runs once per frame? In Flex this is done through invalidateProperties/commitProperties but I don't know the equivalent in Flash.

The code can be optimized a little, but I doubt it will make a difference.

var noteBar = _noteBar;

if(noteBar._decide)
{
    va correctHits = noteBar._correctHits;
    if(correctHits == _noteBar._correctNumberHits)
    {
        _noteBar._totalCorrect = true;
    }
    else if(correctHits > 0) 
    {
    }
    else
    {
        noteBar._decrement = true;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文