I have a rectangle with a percentage 1.0f
this means 100%
so at certain point i set this percentage to 0.0f in another function by mouse click
and now to fill the rectangle back to 100% or 1.0f is where the problem is
I see the rectangle growing back up but never in the right time (time_to_fill_in_seconds)
on update i have the following
private void updateInterface(GameTime gameTime)
{
this.newGameTime += gameTime.ElapsedGameTime.Milliseconds;
if ((rectangle.getPercentage() == 0) &&
(rectangle.getAddValue() == 0))
{
float time = 1000 * time_to_fill_in_seconds;
// update rectangle add values
rectangle.incrementToIn(1.0f, time);
}
rectangle.Update(gameTime);
}
and inside rectangle
// Value to be added on each Update
public void incrementToIn(float targetPercentage, float time)
{
setAddValue((targetPercentage - currentPercentage) / time);
}
public override void Update(GameTime gameTime)
{
if ((percentage <= 1.0f) && (addValue > 0))
{
if (percentage == 1.0f)
addValue = 0;
percentage += addValue;
}
}
I already lost like 2 days searching for the problem…
The bar takes too long to fill
what am i doing wrong?
this is probably something very simple…
if you see something wrong I appreciate your help
thank you
Pheraps I am wrong but it seems that percentage won’t never be 0. In fact Update sets addValue to 0 but not percentage.
Moreover I suggest you to replace the test
percentage == 1
with
percentage >= 1.