Results 1 to 10 of 10

Thread: Pause / resume and fonts

  1. #1

    Pause / resume and fonts

    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
    The Universe is all right here!!!

  2. #2

    Pause / resume and fonts

    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

    Code:
      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

    Code:
    //Maincode loop
    
    Repeat
      CheckForKeyPresses;
      If Pause=False Then 
        begin
          //All the game logic stuff
        end;
      DrawAllToScreen
      Application.ProcessMessages;
    Until Application.Terminated;
    Isometric game development blog http://isoenginedev.blogspot.com/

  3. #3

    Pause / resume and fonts

    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
    The Universe is all right here!!!

  4. #4

    Pause / resume and fonts

    HI again Crisp_N_Dry...........

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

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

    Code:
    //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
    The Universe is all right here!!!

  5. #5

    Pause / resume and fonts

    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 ::
    [pascal]
    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;
    [/pascal]

    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;
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  6. #6

    Pause / resume and fonts

    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.
    ===================

    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
    The Universe is all right here!!!

  7. #7

    Pause / resume and fonts

    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 ::
    [pascal]
    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;
    [/pascal]

    I guess it all depends on how and what you want done?!
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  8. #8

    Pause / resume and fonts

    >> 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;
    Ask me about the xcess game development kit

  9. #9

    Pause / resume and fonts

    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
    The Universe is all right here!!!

  10. #10

    Pause / resume and fonts

    Yes your quite right,,,,


    "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
    The Universe is all right here!!!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •