Jump to content
Willicious

Change "FadeOut" code to "FadeIn" code

Recommended Posts

You can't do the fade-in from the constructor because the form isn't visible at that point.

So:

  1. Create the form.
  2. Set MasterAlpha=0
  3. Show the form
  4. Fade in

I suggest you simply override ShowScreen:

procedure TGameBaseScreen.ShowScreen;
begin
  ScreenImg.Bitmap.MasterAlpha := 0;
  inherited; // Form is made visible here
  FadeIn;
end;

And there was an endless loop in the Fade in method. This one works:

procedure TGameBaseScreen.FadeIn;
var
  EndTickCount: Cardinal;
  TickCount: Cardinal;
  Progress: Integer;
  Alpha, LastAlpha: integer;
const
  MAX_TIME = 1000; // mS
begin
  ScreenImg.Bitmap.DrawMode := dmBlend; // So MasterAlpha is used to draw the bitmap

  TickCount := GetTickCount;
  EndTickCount := TickCount + MAX_TIME;
  LastAlpha := -1;

  while (TickCount <= EndTickCount) do
  begin
    Progress := Min(TickCount - (EndTickCount - MAX_TIME), MAX_TIME);

    Alpha := MulDiv(255, Progress, MAX_TIME);

    if (Alpha <> LastAlpha) then
    begin
      ScreenImg.Bitmap.MasterAlpha := Alpha;
      ScreenImg.Update;

      LastAlpha := Alpha;
    end else
      Sleep(1);

    TickCount := GetTickCount;
  end;
  ScreenImg.Bitmap.MasterAlpha := 255;
end;

Ā 

Share this post


Link to post

@Anders - Brilliant! This last one worked a treat. I copied in the ShowScreen procedure as an overrideĀ and it works great for all screens except the play screen (in this case, it fades from white instead of black). However, I also noticed that the latest version of the FadeOut procedure (the one from theĀ PR) also fades to white on the play screen.

Ā 

So, I'm guessing that this is because FadeIn and FadeOutĀ useĀ MasterAlpha, and somewhere in the Lemmix codebase the background of the play screen is set to white, but I could be wrong. I'll look into this more tomorrow. Thanks again, it's taken a long time to get anywhere with this!

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Ɨ