'change interval dynamically for clicker game
So I already have read other questions about this, but I still do not get it. I am currently learning JS and I am coding a simple clicker game as a project to show to possible employers.
this is my gameData object:
let gameData = {
coins: 0,
coinsPerClick: 1,
upgradeClickCost: 10,
coinsPerSecond: 0,
upgradeSecondCost: 50,
intervalTime: 1000,
intervalReduceCost: 20
};
this should be my interval reduce upgrade to generate a coin every x ms instead of the current 1000 ms
interval_upgrade.addEventListener("click", e => {
gameData.coins = gameData.coins - gameData.intervalReduceCost;
gameData.intervalTime -= 50;
gameData.intervalReduceCost *= 1.5;
interval_time.innerHTML = `Interval time : ${Math.round(gameData.intervalTime)} ms`;
interval_upgrade.innerHTML = `Reduce interval time / Cost = ${Math.round(gameData.intervalReduceCost)}`;
upgrade_control();
upgrade_control_second();
upgrade_control_interval();
i get that i need to stop the former interval and run the new one with the new value for the interval timing. i just do not know how.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
