The app I'm working on has different "screens", which are each essentially large bitmaps. When closing a screen to go to the next one, the following code provides a fade-to-black transition effect:
procedure TGameBaseScreen.FadeOut;
var
Steps: Cardinal;
i: Integer;
P: PColor32;
StartTickCount: Cardinal;
IterationDiff: Integer;
RGBDiff: Integer;
const
TOTAL_STEPS = 32;
STEP_DELAY = 12;
begin
Steps := 0;
StartTickCount := GetTickCount;
while Steps < TOTAL_STEPS do
begin
IterationDiff := ((GetTickCount - StartTickCount) div STEP_DELAY) - Steps;
if IterationDiff = 0 then
Continue;
RGBDiff := IterationDiff * 8;
with ScreenImg.Bitmap do
begin
P := PixelPtr[0, 0];
for i := 0 to Width * Height - 1 do
begin
with TColor32Entry(P^) do
begin
if R > RGBDiff then Dec(R, RGBDiff) else R := 0;
if G > RGBDiff then Dec(G, RGBDiff) else G := 0;
if B > RGBDiff then Dec(B, RGBDiff) else B := 0;
end;
Inc(P);
end;
end;
Inc(Steps, IterationDiff);
ScreenImg.Bitmap.Changed;
Changed;
Update;
end;
end;
Is there any way this same code can be modified to create a new FadeIn; procedure which allows the screen images to fade-in-from-black?
I'm guessing I need to first specify that RGB := 0, 0, 0 and then increase the RGB values until they reach the actual bitmap values. Do I first need to "get" those values somehow? Or, is there a better way to achieve the Fade In/Out procedures? (note that we're dealing with combined bitmaps here, rather than single images)