Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
How to control the paddles in a ping pong game?

I'm making a ping pong game in html canvas , I'm having 4 buttons , 2 for each player to control the paddles but I can't figure out how to control them Adding an "onclick" eventlistener and changing the y velocity , this dosent work as let's assume i pressed the down button for player 1

The paddle will go down but when the button is released the paddle keeps going untill another button is pressed

Let the control buttons be

const p1up = document.getElementById('p1up')
const p1down = document.getElementById('p1down')

const p2up = document.getElementById('p2up')
const p2down = document.getElementById("p2down")

And this is the paddle class

       class paddle {
         constructor(x, y) {
            this.x = x
            this.y = y
            this.ysp = 0
        }
           draw() {
           ctx.fillStyle = "#fff"
           ctx.beginPath()
           ctx.rect(this.x, this.y, 10, 80)
           ctx.fill()
        }
           update() {
           this.y += this.ysp
        }
          limit() {
          this.y = clamp(this.y, 0, area.height)
        }
       }
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda