PDA

View Full Version : Fade and TRect and windowed mode



Wizard
26-02-2008, 12:08 PM
WinXP
Delphi 6
Lib: unDelphiX

Hi everyone, I have the following constructor to implement a fade routine in my game made with DelphiX. Problem is that it only works in full screen mode and not windowed mode. It seems as if image rect tries to draw a rectangle over the whole screen area whereas I need it to draw a rectangle over the control’s client area (the window). Any help is appreciated :-)


Constructor TFade.Create(Parent: TSprite);
var ImageRect : TRect;
Alpha: integer;
begin
inherited Create(Parent);
Alpha := Min(Round(255*0.3),255);
ImageRect.Left := round(0);
ImageRect.Top := round(0);
ImageRect.Right := ImageRect.Left + formGame.dxdrawgame.Width;
ImageRect.Bottom := ImageRect.Top + formGame.dxdrawgame.Height;
formGame.DXImageList.Items[formGame.fadingImageInd ex].DrawAlpha(formGame.DXDrawGame.Surface,ImageRec t,0,Alpha);
end;

Wizard
28-02-2008, 09:35 AM
This is really strange, if it works in full screen mode why not in windowed mode?

And even more strange - it works on my LapTop in windowed mode but not on my PC ... same Delphi, same code and same unDelphiX and the same OS.

Anyone here had the same problem?

Wizard
28-02-2008, 10:59 AM
Got it to work by setting DoFullScreen and DoNoWindowChange and display to 1024 x 768. But, the solution is not desired as there is now an ugly transition from full screen to windowed mode before the app starts :twisted:

So it would seem that the fade can only work properly in full screen mode on my pc, which is very irritating. Unless I'm missing something :?:

User137
28-02-2008, 12:19 PM
... there is now an ugly transition from full screen to windowed mode before the app starts :twisted:
Sounds like badly initialized video, or it is done twice. Have you tried putting off Autoinitialize and then manually call DXDraw.Initialize in formCreate?

Edit: Also you should check if resize events (form or DXDraw) do something undesired when app starts.

Wizard
28-02-2008, 12:32 PM
Thanks, it help's a bit but I can still see how it goes from full screen to the window and it's still ugly. And it's not initialized twice.

I have no rezize events. This is what I now have in formCreate:

DXDrawGame.Finalize;
RestoreWindow;
DXDrawGame.Options := DXDrawGame.Options + [doFullScreen];
DXDrawGame.Options := DXDrawGame.Options + [doNoWindowChange];
DXDrawGame.Display.Width := 1024;
DXDrawGame.Display.Height := 768;
DXDrawGame.Display.BitCount := 16;
DXDrawGame.Initialize;

It works better but not perfectly, when the rezize finishes the icons on my desktop needs to be refreshed. So I suppose I have a choice between that and full screen mode. Unless there's another way to do fade in windowed mode?

Thanks for your help!

User137
28-02-2008, 06:51 PM
You can remove these lines i think :)
DXDrawGame.Finalize;
RestoreWindow;

Wizard
03-03-2008, 11:36 AM
Thanks but I got it to work without initializing full screen. The following needs to be set to true in DXDraw options for the fade routine to work in windowed mode:

doHardware, doDirectX7Mode and do3D, without these set to true it won't work.

One more problem. I'm using stateMachines and now the fade screen is so fast between the title screen/fade/Play that you can hardly see it. However if I use sleep(1000) in the fade create it works and you can properly see the fade.

My question is: is it safe to use sleep() like I'm doing? It seems to be working 100% without any errors...

Memphis
03-03-2008, 12:57 PM
rather then use sleep, why not try a delay function, something like..


procedure Delay(secs: Cardinal);
var
tick: longint;
begin
tick := GetTickCount;
while (GetTickCount-tick) < secs do Application.ProcessMessages;
end;


-MM

Wizard
03-03-2008, 01:16 PM
Ok, that also works and I suppose it's safer than sleep().

Thanks!

I now have:
StartTime : cardinal;
Duration : cardinal;
where StartTime := 0 and
Duration := 1000.


StartTime &#58;= GetTickCount;
while &#40;GetTickCount - StartTime&#41; < Duration do
begin
application.ProcessMessages;
end;

Memphis
03-03-2008, 02:58 PM
for the sake of better assembling, it is worth removing the begin and end....


while &#40;GetTickCount - StartTime&#41; < Duration do
Application.ProcessMessages;

-MM

Wizard
03-03-2008, 05:15 PM
Cool :D

User137
03-03-2008, 05:43 PM
for the sake of better assembling, it is worth removing the begin and end....


while &#40;GetTickCount - StartTime&#41; < Duration do
Application.ProcessMessages;
Are you sure compiler doesn't make this to equal code anyway? Not that i would put begin..end on 1 command cases but still.

Memphis
03-03-2008, 06:49 PM
depends on the configuration and which compiler you use i suppose, but either way it is less symbols for the compiler to handle.