# Frame rate slow down

**URL:** <https://forum.code.org/t/frame-rate-slow-down/35737>\
**Category:** Coding and Debugging Help\
**Created:** [January 19, 2022, 12:30am UTC](https://forum.code.org/t/frame-rate-slow-down/35737 "2022-01-19T00:30:51Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![bobbypen92](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@bobbypen92](https://forum.code.org/u/bobbypen92)\
**Post date:** [January 19, 2022, 12:30am UTC](https://forum.code.org/t/frame-rate-slow-down/35737/1 "2022-01-19T00:30:51Z")

</div>

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 - Code.org](https://studio.code.org/projects/gamelab/rFjCRFJfca1pohaKa61UrKjGcTfPt6_ufKjZjfx3B_Q)

---

<div class="post-metadata">

**Author:** ![CeciliaZ](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/ceciliaz/32/7000_2.png) [@CeciliaZ](https://forum.code.org/u/CeciliaZ)\
**Post date:** [January 19, 2022, 5:33am UTC](https://forum.code.org/t/frame-rate-slow-down/35737/2 "2022-01-19T05:33:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![IMPixel](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/impixel/32/6744_2.png) [@IMPixel](https://forum.code.org/u/IMPixel)\
**Post date:** [January 19, 2022, 1:24pm UTC](https://forum.code.org/t/frame-rate-slow-down/35737/3 "2022-01-19T13:24:45Z")

</div>

Seems fine to me, framerate is high.

---

<div class="post-metadata">

**Author:** ![CeciliaZ](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/ceciliaz/32/7000_2.png) [@CeciliaZ](https://forum.code.org/u/CeciliaZ)\
**Post date:** [January 19, 2022, 8:07pm UTC](https://forum.code.org/t/frame-rate-slow-down/35737/4 "2022-01-19T20:07:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![IMPixel](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/impixel/32/6744_2.png) [@IMPixel](https://forum.code.org/u/IMPixel)\
**Post date:** [January 19, 2022, 10:39pm UTC](https://forum.code.org/t/frame-rate-slow-down/35737/5 "2022-01-19T22:39:11Z")

</div>

![image](https://us1.discourse-cdn.com/flex016/uploads/codeorgforum/original/2X/f/fca008082bd0d58b4177724a51da0165d819d8be.png)  
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?

---

<div class="post-metadata">

**Author:** ![bobbypen92](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@bobbypen92](https://forum.code.org/u/bobbypen92)\
**Post date:** [January 20, 2022, 11:29am UTC](https://forum.code.org/t/frame-rate-slow-down/35737/7 "2022-01-20T11:29:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bobbypen92](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@bobbypen92](https://forum.code.org/u/bobbypen92)\
**Post date:** [January 20, 2022, 11:40am UTC](https://forum.code.org/t/frame-rate-slow-down/35737/8 "2022-01-20T11:40:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bobbypen92](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@bobbypen92](https://forum.code.org/u/bobbypen92)\
**Post date:** [January 21, 2022, 1:44am UTC](https://forum.code.org/t/frame-rate-slow-down/35737/9 "2022-01-21T01:44:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![IMPixel](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/impixel/32/6744_2.png) [@IMPixel](https://forum.code.org/u/IMPixel)\
**Post date:** [January 25, 2022, 12:02am UTC](https://forum.code.org/t/frame-rate-slow-down/35737/10 "2022-01-25T00:02:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![timothy\_brinkley](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/timothy_brinkley/32/6448_2.png) [@timothy\_brinkley](https://forum.code.org/u/timothy_brinkley)\
**Post date:** [April 22, 2022, 11:09pm UTC](https://forum.code.org/t/frame-rate-slow-down/35737/11 "2022-04-22T23:09:23Z")

</div>

> [@bobbypen92](#):
>
> lastMoveTime var I’m using, which is grabbed from World.frameCount

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