Coder Social home page Coder Social logo

Noticeable input lag. about javascript-snake HOT 6 OPEN

patorjk avatar patorjk commented on August 15, 2024
Noticeable input lag.

from javascript-snake.

Comments (6)

patorjk avatar patorjk commented on August 15, 2024

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.

from javascript-snake.

joereynolds avatar joereynolds commented on August 15, 2024

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

from javascript-snake.

patorjk avatar patorjk commented on August 15, 2024

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.

from javascript-snake.

samkcarlile avatar samkcarlile commented on August 15, 2024

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.

from javascript-snake.

patorjk avatar patorjk commented on August 15, 2024

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.

from javascript-snake.

Coteh avatar Coteh commented on August 15, 2024

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

from javascript-snake.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.