JavaScript-Snake icon indicating copy to clipboard operation
JavaScript-Snake copied to clipboard

Noticeable input lag.

Open joereynolds opened this issue 8 years ago • 6 comments

If you do down + right (or any combination really) multiple times, you can see that snake will still be doing those movements even after you've finished typing. I'm assuming this is because it's gridded rather than just a free amount of pixels but still...

joereynolds avatar May 07 '16 19:05 joereynolds

This is because the game queues key presses. If key presses aren't queued, you can miss some (ex: someone can press down + right really quickly and only go down because the game wasn't ready for the next key press. This would lead the snake into not going right and make the player feel like the game didn't register their right key press). However, I can see how it would cause the lag effect if down+right were pressed repeatedly really quickly. I'll have to think about this, not sure what the best solution would be.

patorjk avatar May 09 '16 15:05 patorjk

In that case I think the real question is, how is it missing/discarding keypresses?

joereynolds avatar May 10 '16 13:05 joereynolds

The snakeSpeed determines the rate of how fast the snake moves. At each tick the game checks to see which direction it will move. The direction the snake moves is based on the arrow keys, when an arrow key is typed the direction is changed. If the user presses two keys within the snakeSpeed time period / tick period (ex: right+down), then only the last key will register if queuing isn't done.

patorjk avatar May 10 '16 13:05 patorjk

I have an idea that may work. How about attaching a time with each move in the queue and then for every tick, checking whether too much (this could be defined) time has passed to actually execute the move. That way if one was to press multiple arrow keys in a small amount of time, there wouldn't be 'residual moves' per se if the move is too old.

samkcarlile avatar May 10 '16 15:05 samkcarlile

That's an interesting idea, thank you Sam. When I get a chance in the next few days I'll try and dive into this deeper.

patorjk avatar May 11 '16 14:05 patorjk

@dginovker was telling me that #56 fixes this issue.

Coteh avatar Oct 18 '19 18:10 Coteh