How to detect a collision with JS
I am making my first game in canvas + javascript, just a space shooter. The problem is that I am using two nested loops to check if the missile hits the enemy like this:
if((enemies[i][1]>rocket_posy&&enemies[i][1]<rocket_posy+40)&&enemies[i]0]>rocket_posx&&enemies[i][0]<rocket_posx+12))
and this causes a small but still annoying lag. I've looked into this here and on google, but no one seems to bother with this as we have different mechanisms to do this. Does anyone know how to solve this problem without nested loops?
Thanks for the answer!
+3
source to share