it is necessary that when the plane collided with a bird, the plane fell and the control was turned off, tried it like this, it still does not turn off

document.addEventListener("keydown", keydownmove); document.addEventListener("keyup", keyupmove); function keydownmove(e) { if (e.keyCode == 37) { left = true; } if (e.keyCode == 38) { up = true; } if (e.keyCode == 39) { right = true; } if (e.keyCode == 40) { down = true; } if (game_over == true) { return false; } } function keyupmove(e) { if (e.keyCode == 37) { left = false; } if (e.keyCode == 38) { up = false; } if (e.keyCode == 39) { right = false; } if (e.keyCode == 40) { down = false; } } if (up == true) { yPlane -= 4; } if (left == true) { xPlane -= 4; } if (right == true) { xPlane += 4; } if (down == true) { yPlane += 4; } if (game_over == true) { yPlane +=5; } 

Closed due to the fact that the essence of the question is not clear to the participants of Kostiantyn Okhotnyk , 0xdb , freim , aleksandr barakin , LFC on Feb. 9 at 10:12 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • So-so you have a plane - Kostiantyn Okhotnyk February
  • Show the function in which you are trying to disable control. - Egor Zholnin

1 answer 1

To solve your problem, simply unzip the click handlers:

 //Допустим, у Вас есть объект plan, который отвечает за поведение самолета, тогда plan.onCrash = function() { this.removeEventListener("keydown", keydownmove) this.removeEventListener("keyup", keyupmove) }