function collision(){
if(player.y + player.height + player.velocityY >= coin.y &&
player.x + player.width >= coin.x &&
player.x <= coin.x + coin.width){
score = +1
}
}
Right now my collision works but only once, ei if my player collides with two points it only adds one which makes sense because if statement only get read once. How can I put this function in a loop? I tried with while loop but it gave me call stack exceeded.
>Solution :
You need a game loop. In javascript, the simple way is using setInterval
The setInterval() method calls a function at specified intervals (in milliseconds).
const FPS = 30; // frames per second
setInterval(collision, 1000 / FPS);