PDA

View Full Version : Pause / resume and fonts



atozix
21-10-2003, 11:27 AM
Hi agin all,,,

How do I get a program using delphix to pause at any point. and wait till a user hits a key or mouse button and then resume processing???

and a really easy one .. I can set font size, color etc,, But how do I set the actual font???

cheeeeeerrrrrrrrssssssss a

Crisp_N_Dry
21-10-2003, 01:55 PM
The font part is easy enough. Just set name part of the font properties. For example Font.Name:='Arial';

For the pause thing, one way of doing it would be to have a global variable called Pause: Boolean. And then in your main code loop, have a check to see if this boolean is true, if it is then do not execute the main code, if not then continue as normal. To activate it and deactivate you just need to run a check for a certain key press, such as 'P', and when this key is pressed


If Pause=True Then Pause:=False Else Pause:=True;

Just make sure that your key press handler is not inside the pause check code, otherwise as soon as it goes into pause mode, you will not be able to get out. This will not matter if you are usin the Form.OnKeyDown method but will matter if you are using your own keypress handler.

Example


//Maincode loop

Repeat
CheckForKeyPresses;
If Pause=False Then
begin
//All the game logic stuff
end;
DrawAllToScreen
Application.ProcessMessages;
Until Application.Terminated;

atozix
21-10-2003, 08:32 PM
Hi Crisp_N_Dry,,,

The Font.Name:='xxxx'; works fine ...:) thx...

Will have to pontificate on the pause method as
I dont really have a main game loop as such...

My game is just a loose sketch for a start, using all the standard delphix sprite routines....domove, collision, ontimer, etc... It just started to help me learn delphix, but now I will have to reorganize it to be more structured ...

thx and cheeeeeeeerrrrrrssssssss a

atozix
24-10-2003, 01:12 AM
HI again Crisp_N_Dry...........:)


The font part is easy enough. Just set name part of the font properties. For example Font.Name:='Arial';


If Pause=True Then Pause:=False Else Pause:=True;

Example


//Maincode loop

Repeat
CheckForKeyPresses;
If Pause=False Then
begin
//All the game logic stuff
end;
DrawAllToScreen
Application.ProcessMessages;
Until Application.Terminated;
===================================
===================================

OK then,, I have been trying to instigate this method... But my current inadequacy and lack of understanding of Delphi are making it difficult to get it to work...

If I am using the Form OnKeyDown,, How do I ensure that the
CheckForKeyPresses; call, actually calls or accesses the OnKeyDown procedure????

Alternatively,,, and I would like to be able to do this also ... How do I write my own keyboard event handler???

Am still trying to get my head around Delphi and find it all rather confusing...

Treat me like a novice and be explicit.... THX and
BTW I would write

Pause := not Pause; // to just toggle the pause condition

If Pause=True Then Pause:=False Else Pause:=True


cheeeeeeeeerrrrrrsssssssss atozix :wink:

M109uk
24-10-2003, 01:21 AM
Alternatively,,, and I would like to be able to do this also ... How do I write my own keyboard event handler???


This is something i use in the OnTimer event of a TTimer ::

type
TVirtualKeyCode = Integer;

function IsKeyDown(c : Char): Boolean; overload;
function IsKeyDown(vk : TVirtualKeyCode): Boolean; overload;

implementation

function IsKeyDown(c : Char) : Boolean;
var
vk : Integer;
begin
// '$FF' filters out translators like Shift, Ctrl, Alt
vk:=VkKeyScan(c) and $FF;
if vk<>$FF then
Result:=(GetAsyncKeyState(vk)<0)
else Result:=False;
end;

// IsKeyDown
//
function IsKeyDown(vk : TVirtualKeyCode) : Boolean;
begin
Result:=(GetAsyncKeyState(vk)<>0);
end;


To use the Virtual Key Codes you will need to add 'Windows' to your uses list.

You use them like ::
If IsKeyDown(VK_UP) Then
Begin
// Move forwards
End;

Or ::
If IsKeyDown('U') Then
Begin
// Do something
End;

atozix
24-10-2003, 07:08 AM
Hi M109uk,,,, :)

THX for the reply... I shall digest your information and addit to my armoury....

BTW thats a pretty impressive suit of armour on your avatar pic. :D
===================

I also managed to use the DelphiX DXInput to get a working pause finally
but I am unsure about the isButton values??

procedure TForm1.pause;
begin
repeat
DXInput1.Update;
with DXDraw1.Surface.Canvas do
begin
Brush.Style := bsClear;Font.Color := clWhite;Font.Size := 12;
Textout(200,300,'THIS IS A PAUSE ROUTINE. ');
Release;
end;
DXDraw1.Flip;
until (isLeft in DXInput1.States) or (isButton1 in DXInput1.States);
userpause:= false;
end;
======================

cheeeeeeeeerrrrrrrrssssssss atozix

M109uk
24-10-2003, 05:32 PM
Hi atozix,


I also managed to use the DelphiX DXInput to get a working pause finally
but I am unsure about the isButton values??

procedure TForm1.pause;
begin
repeat
DXInput1.Update;
with DXDraw1.Surface.Canvas do
begin
Brush.Style := bsClear;Font.Color := clWhite;Font.Size := 12;
Textout(200,300,'THIS IS A PAUSE ROUTINE. ');
Release;
end;
DXDraw1.Flip;
until (isLeft in DXInput1.States) or (isButton1 in DXInput1.States);
userpause:= false;
end;


Im not to sure about that, i have'nt really used DelphiX for years, but im sure when i used it, it came with a demo showing how to use TDXInput?!
Dont you set the values of the isButtons in the TDXInput, hmm i could be thinking of a different Engine though :s

You could use the code i gave you earlier by ::

procedure TForm1.pause;
begin
repeat
DXInput1.Update;
with DXDraw1.Surface.Canvas do
begin
Brush.Style := bsClear;Font.Color := clWhite;Font.Size := 12;
Textout(200,300,'THIS IS A PAUSE ROUTINE. ');
Release;
end;
DXDraw1.Flip;
until (IsKeyDown(VK_LEFT)) or (IsKeyDown(VK_LBUTTON));
userpause:= false;
end;


I guess it all depends on how and what you want done?!

Harry Hunt
24-10-2003, 07:40 PM
>> If Pause=True Then Pause:=False Else Pause:=True;

Just for the sake of contributing something to this thread... the above obviously equals Pause := not Pause;

atozix
24-10-2003, 07:42 PM
Hi M109uk,,, :)

Yes,, I have digested and am ready to regurgitate ... your info has been a great help and now I have a good choice as to what method to use...

THX again ....

Cheeeeeeeerrrrrrrssssss ato

atozix
24-10-2003, 11:14 PM
Yes your quite right,,,,
8)

"You can also bind up to 32 other keys using the Editor ( Double click on the DXinput control to access this ) You can have up to 3 keys bound to a single action."

THX to
http://www.cerebral-bicycle.co.uk/

cheeeerrrrrrrrsssssss ato