I am currently developing a game and I'm looking to adjust the setInterval property to enhance the responsiveness of a spaceship in the game (currently set as setInterval(loop, 1000 / 40)). To achieve this, I have added a range slider with values ranging from 1 to 3. Below is the code snippet:
Range Slider:
<input type="range" id="sensibilty" min="1" max="3" value="2">
Sensitivity Adjustment:
const loop = function() {
if (keys[37] || keys[65]) {pos.left -= 10}
if (keys[39] || keys[68]) {pos.left += 10}
if (keys[38] || keys[80]) {pos.top -= 1}
if (keys[40] || keys[75]) {pos.top += 1}}
let sens = setInterval(loop, 1000 / 40);
let sensitivity = document.getElementById("sensibilty").value;
if (sensitivity == "1") {clearInterval(sens); setInterval(loop, 1000 / 30)}
else if (sensitivity == "3") {clearInterval(sens); setInterval(loop, 1000 / 60)}
The current setup is not functioning properly, can anyone suggest adjustments to the setInterval values? Thank you!