# Skill button cooldown

When a spell is on cooldown I display a "unfilling" black bar over the spell GUI until the cooldown is reached. Problem is when i have more than one second of cooldown the scale of the "unfilling" black bar getting strange outcome. I have found the calculation from this website https://gamedevelopment.tutsplus.com/tutorials/how-to-code-hud-cooldown-bars--cms-20983 at the article Skill Buttons Cooldown

float cooldownTime = 1000.0f; //milliseconds.
long elapsedTime = System.currentTimeMillis(); //This is called every second in the main loop
float cooldownEndTime = elapsedTime + cooldownTime;
guiTexture.scale.y = 0.06f; //The "unfilling" black bar over the sprite. 0.06 = cover the whole spell GUI
//When i try to change the scale of the "unfilling" black bar i use this code.
scale.y = (0.06f*(elapsedTime/1000)) - (((0.06f*(elapsedTime/1000))/cooldownEndTime) * elapsedTime);


I have tried to modify the calculation but I havent succeed. If anyone have tackle this problem before or can help me reache a soultion i would be grateful. Thanks

elapsedTime (current Java time always) over cooldownEndTime (predicted 1000ms in future) multiplied by maximum bar height 0.06f;
That is scale.y = (elapsedTime/cooldownEndTime)*0.06f; giving you a fraction scaled by a bar height.