I'm making a game where you can earn money at a steady rate (ex. 50 dollars a second). However, when increasing "money", I want it to smoothly increase, not jump 50 dollars every second.
setInterval(increasemoney,1000);
function increasemoney() {
money = money + moneypersecond;
}
My current strategy is to divide it into two categories; one where you earn 1 dollar per 1/moneypersecond seconds (where moneypersecond < 1000), and one where you earn y dollars per 0.001 seconds.
However, there are two issues; because I want to avoid floats, y has to be rounded, but that will lose precision. Edit: Floats are FINE! I can also increase precision by increasing the time between "updates" (which also makes it look less smooth, and only increases precision instead of removing the imprecision).
My questions:
- Is this the right track?
- How should I implement the solution? (Preferably in a way that removes imprecision)
Requirements: I want to avoid floats Edit: Floats are okay, and the more accurate the better.
question from:
https://stackoverflow.com/questions/65942476/smoothly-increase-a-variable 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…