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

222
Vistas
¿Cómo puedo detectar cuando un componente sale del lienzo?

Estoy tratando de implementar un mecanismo de disparo como en el original.

No sé cómo saber si solo existe un proyectil y cuándo sale de la pantalla superior para que el jugador pueda disparar de nuevo.

 if (gameArea.key === "Space") { playerProjectile = new component(2, 7, "white", player.x + player.width /2, player.y); playerProjectile.speedY = +2;

Inicializo un nuevo componente cuando el jugador presiona la barra espaciadora. Necesita verificar si todavía hay un proyectil en la pantalla y si ha salido de la pantalla.

Aquí está mi función componente:

 function component(width, height, color, x, y) { this.width = width; this.height = height; this.speedX = 0; this.speedY = 0; this.x = x; this.y = y; this.update = function () { ctx = gameArea.context; ctx.fillStyle = color; ctx.fillRect(this.x, this.y, this.width, this.height); } this.playerNewPos = function () { this.x += this.speedX; if (this.x < 0) { player.x = 0; } else if (this.x > gameArea.canvas.width - player.width) { player.x = gameArea.canvas.width - player.width; } } this.playerProjectileNewPos = function () { this.y -= this.speedY; }
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