Comments (6)
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.
In that case I think the real question is, how is it missing/discarding keypresses?
from javascript-snake.
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.
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.
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.
@dginovker was telling me that #56 fixes this issue.
from javascript-snake.
Related Issues (20)
- vvbh
- Too Fast HOT 3
- Snake-game multiplayer HOT 4
- I need wasd keys PLEASE HOT 2
- No package.json HOT 1
- Make highscore be permanently visible at the bottom
- Input Edge Case Issue HOT 1
- Game crashes when snake fills up board HOT 6
- Highscore check doesn't seem to work anymore HOT 1
- Add pause button HOT 2
- Add gamepad support
- New Theme HOT 1
- Social links on bottom of page. HOT 51
- Snake collision HOT 3
- Wait for an arrow-key press after coming out of pause.
- Snake's head should be a different color. HOT 2
- Snake's body should be visibly joined together
- Theme selector dose not display correct theme
- Pause when user moves to a different tab HOT 2
- Add allcontributors section HOT 34
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from javascript-snake.