views:

49

answers:

2

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?

+1  A: 

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.

Sam
Great. I'll try this for the classes that affect the movieclip. Thanks.
Miles
Okay. I isolated the problem, and the framerate is silky smooth. Thanks!
Miles
A: 

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;
    }
}
Sam
Thanks. It turns out that the '_totalCorrect' variable added a new MC to the displaylist every time set true, which accounted for the slow down.
Miles