Frame rate slow down

Put together a little copy of this old phone just to test Game Lab out, but a little while into the game the frame rate begins to slow dramatically. It does not seem to happen in any relation to a game event, and happens at different time each time. Any ideas why?

Here’s the link to the game: Game Lab -

First of all welcome to the Code Teacher Forum!
I think it’s the way you are using World.frameCount. Maybe you want to use World.seconds in the equations to assign the numbers to the variables.

When you hover over blocks in your toolbox it will show a link, when you click “see example” for World.frameCount it says this:
This keeps track of the number of frames that have been displayed since the program started.

frameCount is incremented once for every execution of the draw() loop. frameCount is a variable that you do not need to declare. frameRate is the number of times per second the screen is refreshed is also the speed of draw() loop. The default rate of 30 frames per second that have been displayed since the program started.

So when you use this variable in line 129 that is going to be a huge number which then affects everything else. And the number assigned to last move will also depend on how long someone looked at the home page before beginning to play.

Hope this helps. Let me know if you have any other questions.

Seems fine to me, framerate is high.

What you described, slowing down, happened when I played it.

I’ve played the game for a while… Frame rate is still at 30. How much do you need to play for the frame rate to drop?

My frame rate drops, usually from the normal 30-25 or so down to half that or less, within 30 seconds to a minute of play

Thanks for taking a look.

I’m not sure this is the problem, though. I ran it and console.logged frame rate in relation to the lastMoveTime var I’m using, which is grabbed from World.frameCount.

Early in the game, it was:

  • 28

  • “FR = 27.70083100663603”

Later, it was:

  • 980

  • “FR = 10.040160640166906”

So the var is not that big (less than 1000 still) and the frame rate has dropped by two-thirds.

I tried using World.seconds originally, but it didn’t want to let me increment the movement of the snake at anything less that once each second. I used frame Rate so I can get the snake moving faster.

So I rewrote the moveSnake function with a Timed Loop. Simpler and works better, but still have the frame rate slow down.

I also thought it might be something in the moveFood function, because I was checking to make sure the food does not reappear on the snake’s head or another food, but the frame rate slow down still appears even after stripping down this function.

Even updated Chrome in case it was some browser issue. No effect.

Use a watcher, using console.log too many times results in a frameRate drop.

1 Like

Thanks IMPixel, what you wrote helped me a lot. I was scratching my head for a good week before I found this.