I always split my functionality in an update and a render procedure.
So in my gameengine.update I do things like this:
Code:
if UI.FadeDir = 1 then
begin
UI.FadeAlpha := min($FF, UI.FadeAlpha + 15*time_);
if UI.FadeAlpha = $FF then
begin
// PERFORM THE REASON FOR FADEOUT HERE (eg change gamestate)
UI.FadeDir := 2;
end;
end;
if UI.FadeDir = 2 then
begin
UI.FadeAlpha := max($0, UI.FadeAlpha - 15*time_);
if UI.FadeAlpha = $0 then
UI.FadeDir := 0;
end;
Then in my UI.render I do this:
Code:
if (FadeAlpha <> 0) then
begin
DanJetX.Zbuffer := false;
DanJetX.Primitives2D.Rectangle(0,0,DanJetX.width,DanJetX.height,trunc(FadeAlpha) shl 24);
DanJetX.Zbuffer := true;
end;
The point is, I don't need seperate gamestates for fading out or in. I just set UI.FadeDir to 1 and the show begins.
PS: UI is my UserInterface class... and since this is always rendered after all other things, I perform the rectangle there, embedded in the User Interface. This way I can also set a flag if the whole screen should be faded or only game content and the UI remains...
I think DelphiX has a rectangle function, so this is a really easy task to do.
Bookmarks