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

244
Views
¿Por qué sigue arrojando un error de variable indefinida de lectura cuando ESTÁN definidas?

Entonces... me sale un error:

 "<a class='gotoLine' href='#101:18'>101:18</a> Uncaught TypeError: Cannot read properties of undefined (reading 'x')"

Cuando ejecuto esto:

 var Canvas = document.getElementById('ViewPort'); var Context = Canvas.getContext("2d"); Canvas.width = 250; Canvas.height = 250; Canvas.style.border = "1px solid black"; var Objects = []; //Testing Objects.push({ x: 50, y: 50, width: 50, height: 50, style: "black", }) Objects.push({ x: 55, y: 55, width: 50, height: 50, style: "blue", }) //End Testing function RenderObjects() { for (var i = 0; i < Objects.length; i++) { for (var j = 0; j < Objects.length; j++) { if (Hitting(Object[i], Object[j])) { console.log("Hitting object " + j); console.log(Object[j]) } else { Context.fillStyle = Objects[i].fillstyle; Context.fillRect(Objects[i].x, Objects[i].y, Objects[i].width, Objects[i].height); } } } } function Hitting(rectA, rectB) { return !(rectA.x + rectA.width < rectB.x || rectB.x + rectB.width < rectA.x || rectA.y + rectA.height < rectB.y || rectB.y + rectB.height < rectA.y); } RenderObjects();
 <canvas id = "ViewPort"></canvas>

¿Cual es el problema? He leído mi código y no puedo encontrar ningún problema. Debería representar dos objetos en un lienzo HTML; siempre que no choquen.

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

0

Solo debes corregir algún error tipográfico.

 var Canvas = document.getElementById('ViewPort'); var Context = Canvas.getContext("2d"); Canvas.width = 250; Canvas.height = 250; Canvas.style.border = "1px solid black"; var Objects = []; //Testing Objects.push({ x: 50, y: 50, width: 50, height: 50, style: "black", }) Objects.push({ x: 55, y: 55, width: 50, height: 50, style: "blue", }) //End Testing function RenderObjects() { for (var i = 0; i < Objects.length; i++) { for (var j = 0; j < Objects.length; j++) { if (Hitting(Objects[i], Objects[j])) { //instead of Object[i], Object[j] console.log("Hitting object " + j); console.log(Objects[j]) //instead of Object[j] } else { Context.fillStyle = Objects[i].fillstyle; Context.fillRect(Objects[i].x, Objects[i].y, Objects[i].width, Objects[i].height); } } } } function Hitting(rectA, rectB) { return !(rectA.x + rectA.width < rectB.x || rectB.x + rectB.width < rectA.x || rectA.y + rectA.height < rectB.y || rectB.y + rectB.height < rectA.y); } RenderObjects();
 <canvas id = "ViewPort"></canvas>

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!