Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

99
Visualizações
Trying to throttle just for the jump keypress Javascript HTML5 Canvas Game

Still new at this, have been searching and searching. I see some answers but the code looks a bit different from mine using var and a few others. I found this code to use.

function throttle(cb, delay = 2000) {
  let shouldWait = false

  return (...args) => {
    if (shouldWait) return

    cb (...args)
    shouldWait = true

    setTimeout(() => {
      shouldWait = false
    }, delay)
  }
}

To my understanding that part is correct. I have the basic movement keys. I only want to throttle the jump keypress. Case 87: any help would be greatly appreciated. Trying to avoid players tapping the jump button to fly everywhere. I've tried other alternatives but throttling would solve my problem.

addEventListener('keydown', ({ keyCode }) => {
  if (game.disableUserInput) return
  var lastEnter = null;

  switch (keyCode) {
    case 65:
      console.log('left')
      keys.left.pressed = true
      lastKey = 'left'

      break

    case 83:
      console.log('down')
      break

    case 68:
      console.log('right')
      keys.right.pressed = true
      lastKey = 'right'

      break

    case 87: // W
      console.log('up')    
      if (event.repeat) { return }
      player.velocity.y -= 25           

      break
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda