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

180
Views
Cálculo de colisión defectuoso al usar getLocalBounds en PIXIJS

Tengo una consulta sobre los tamaños de los gráficos. Estoy tratando de codificar la detección de colisiones, mi código es el siguiente:

 const collided = (objectBounds, bounds) => { return ( objectBounds.x + objectBounds.width > bounds.x && bounds.x + bounds.width > objectBounds.x && objectBounds.y + objectBounds.height > bounds.y && bounds.y + bounds.height > objectBounds.y ); }; const restrictPosToObjectBounds = (objectBounds, bounds, oldBounds) => { if (collided(objectBounds, bounds)) return oldPos; else return { x: bounds.x, y: bounds.y }; };

Y luego lo llamaré así:

 const objectPosition = object.getLocalBounds() const oldPosition = object.getLocalBounds() restrictPosToObjectBounds ( objectPosition, { ...getNewPos(oldPosition), width:oldPosition.width, height:oldPosition.height, }, oldPosition )

Lo cual funciona un poco, pero habría una gran brecha alrededor del objeto con el que estoy chocando, dejándome incapaz de chocar correctamente con él.

ingrese la descripción de la imagen aquí

Si cambio mi función de colisión a esto (dividiendo el ancho y las alturas por la mitad)

 const collided = (objectBounds, bounds) => { return ( objectBounds.x + objectBounds.width / 2 > bounds.x && bounds.x + bounds.width / 2 > objectBounds.x && objectBounds.y + objectBounds.height / 2 > bounds.y && bounds.y + bounds.height / 2 > objectBounds.y ); };

ingrese la descripción de la imagen aquí

Entonces funciona correctamente, ¿alguna idea de por qué? ¿La escala de un gráfico se representa de manera diferente o algo así? ¿Cómo obtiene su ancho y alto exactos?

about 4 years ago · Juan Pablo Isaza
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!