Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
El nuevo operador de JavaScript hace que las variables sean nulas

Al crear una instancia de una clase, obtuve un valor nulo.

Hice Class Projectile como se muestra a continuación.

 class Projectile { constructor(time, x, y, radius, color, velocity) { this.time = time; this.x = x; this.y = y; this.radius = radius; this.color = color; this.velocity = velocity; }

Este new método creó una clase válida con propiedades x e y no nulas.

https://github.com/ekusiadadus/shootgame/blob/fb93a96c5eb071dad68b57da9fb4c87e7c572baa/index.html#L361

 addEventListener("click", (event) => { const angle = Math.atan2( event.offsetY - canvas.height / 2, event.offsetX - canvas.width / 2 ); const velocity = { x: Math.cos(angle) * 5, y: Math.sin(angle) * 5 }; var time1 = (new Date() - time) / 1000; if (gameState === true) answer.push(JSON.stringify(new Ans(time1, velocity.x, velocity.y))); projectiles.push( new Projectile( time1, canvas.width / 2, canvas.height / 2, 5, "white", velocity ) ); console.log(`projectiles = ${JSON.stringify(projectiles)}`); });

Pero en esta línea, el mismo método new creó una clase con propiedades x e y nulas. https://github.com/ekusiadadus/shootgame/blob/fb93a96c5eb071dad68b57da9fb4c87e7c572baa/index.html#L380

 function checkBullet() { var timer = setInterval(() => { if (gameState === false) clearInterval(timer); let time1 = (new Date() - time) / 1000; submittion.forEach((p, i) => { if (p.time <= time1 && p.used === false) { projectiles.push( new Projectile( p.time, canvas.width / 2, canvas.height / 2, 5, "white", [px, py] ) ); p.used = true; console.log(`projectiles1 = ${JSON.stringify(projectiles)}`); } }); }); }

¿Cuál es la diferencia de ellos? ¿Y cómo solucionarlos?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

 if (p.time <= time1 && p.used === false) { projectiles.push( new Projectile( p.time, canvas.width / 2, canvas.height / 2, 5, "white", [px, py] ) );

[px, py] no es correcto....

Un miembro de velocidad no es una matriz, sino un dict.

En lugar de [px, py] , {x:px, y:py} resuelve este problema.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!