So for a University Project I am looking to try and change the tint of a sprite over a specific time frame. The aim is to make a set of rocks turn from grey to orange (simulating heating them up) over 5 seconds, then turn them from orange to grey again (simulating cooling them down) over the next 5 seconds.
This is done using the DirectXTK, SpriteBatch specifically, however I appear to be having some problems controlling the heating up and cooling down logic. Currently, the rocks heat up to orange, but do not cool back down.
The Update function for the rocks, along with a further HeatDelay function I am using to control the cooling down are are included below.
timeToChangeColour is initialised at 5.
void RockFade::Update(float timeDelta)
{
if ((timeDelta >= timeToChangeColour) && (heatDelay == false))
{
this->heatUp = false;
HeatDelay();
timeToChangeColour = timeDelta + 10;
}
else if ((timeDelta < timeToChangeColour) && (heatDelay == false))
{
this->heatUp = true;
}
if (heatUp)
{
this->newBlue -= 0.002f;
}
else
{
this->newBlue += 0.002f;
}
this->spriteTint = DirectX::SimpleMath::Color{ 1.0f, 1.0f, newBlue, 1.0f};
}
void RockFade::HeatDelay()
{
heatDelay = true;
Sleep(5);
heatDelay = false;
}
Any help is greatly appreciated!