Results 1 to 10 of 10

Thread: Showing message on screen for fixed time period

  1. #1

    Showing message on screen for fixed time period

    OS: WINXP
    LIB: DELPHIX

    Hi everyone. I would like to display a message on the screen indicating that a bonus life is awarded. At the moment the message is displayed as per the code below, problem is that points can be scored faster or slower and the time that the message is displayed is directly connected to scoring. I would like the message to be displayed for 3 or 5 seconds independent of the scores. ie If points reaches 25000, 50 000 etc the message must be shown for 5 seconds.

    Thanks!

    [pascal]if ((points >= 25000) and (points <= 27000)) then
    begin
    dxFontBonus.TextOut(dxDrawGame.Surface,300,330,'Bo nus Life');
    end;[/pascal]
    Wake up from the dream and live your life to the full

  2. #2

    Showing message on screen for fixed time period

    you need something independent of the scoring.

    I would create a sprite class for this.
    Create it when the bonus is achieved and add a new instance to the sprite engine.

    The TBonusSprite instance would count down a fixed number of ticks (or it could be time based, your call) and then die... possibly even setting it's alpha value on the way so you get a nice fade out. The text would be provided by an image... or you could useTextOut, but you can make it very dramatic by using an image.

    You can also make it play a sound ("BONUS!!!!" in a deep echoing voice) and also maybe create a particle effect.. all of this by creating one object when a bonus is received.

    Your call, but that's how I would do it.

  3. #3

    Showing message on screen for fixed time period

    Place a TTimer component on your form, set its Interval on 5000, its Enabled on False and paste this in its OnTimer event:
    Code:
    dxFontBonus.TextOut&#40;dxDrawGame.Surface,300,330,'Bonus Life'&#41;;
    An then somewhere:
    Code:
    if &#40;points >= 25000&#41; and &#40;points <= 27000&#41; then
      Timer1.Enabled &#58;= True;
    Hope that helps :!:

  4. #4

    Showing message on screen for fixed time period

    Quote Originally Posted by Brainer
    Place a TTimer component on your form, set its Interval on 5000, its Enabled on False and paste this in its OnTimer event:
    Code:
    dxFontBonus.TextOut&#40;dxDrawGame.Surface,300,330,'Bonus Life'&#41;;
    An then somewhere:
    Code:
    if &#40;points >= 25000&#41; and &#40;points <= 27000&#41; then
      Timer1.Enabled &#58;= True;
    Hope that helps :!:
    This will not help because it will show the text for hours if the player stops scoring after reaching 25000 points.

    In addition to that, if I read your code right, it will let the text blink every 5 seconds for a wink of an eye
    <a href="http://www.greatgamesexperiment.com/game/Valgard/?utm_source=gge&amp;utm_medium=badge_game"><img border="0" alt="GGE" title="GGE" src="http://static.greatgamesexperiment.com/badge/game/valgard/gge400x56.png"></a>

  5. #5

    Showing message on screen for fixed time period

    Brainer, from what I've read it's not wise to have TTimer with the DelphiX timer.

    What about TimeGetTime?

    Something like:

    procedure TFormGame.BonusLife;
    var BonusTime : single;
    begin
    BonusTime := timegettime + 3000;
    if timegettime <BonusTime>= 5000) then
    begin
    dxFontBonus.TextOut(dxDrawGame.Surface,300,330,'Bo nus Life');
    end;
    end;
    doesn't work -- any suggestions?
    Wake up from the dream and live your life to the full

  6. #6

    Showing message on screen for fixed time period

    I would do it like that:

    Code:
    type TMessage = record
      NeededPoints &#58; integer;
      Text &#58; string;
      StartTime &#58; cardinal;
      Duration &#58; cardinal;
    end;
    
    var BonusMsg &#58; TMessage;
    .
    .
    .
    
    // init the Record
    with BonusMsg do
      Text &#58;= 'Bonus life!';
      NeededPoints &#58;= 25000;
      StartTime &#58;=  0;
      Duration &#58;= 5000;
    end;
    .
    .
    .
    
    // Show the message
    if &#40;score >= BonusMsg.NeededPoints&#41; then
    begin
      with BonusMsg do
      begin
        StartTime &#58;= GetTickCount;
        inc&#40;NeededPoints, 25000&#41;;
      end;
    end;
    
    .
    .
    .
    
    // rendering in your render routine
    if GetTickCount - BonusMsg.StartTime < BonusMsg.Duration then
      dxFontBonus.TextOut&#40;dxDrawGame.Surface,300,330,BonusMsg.Text&#41;;

    Code written straight outta my head. No guarantee for compilable code, but it should show the idea...

    Away from that, personally I would use a simple particle to show the text!


    EDIT: I edited the code so that it should spawn the text each 25000 points!
    <a href="http://www.greatgamesexperiment.com/game/Valgard/?utm_source=gge&amp;utm_medium=badge_game"><img border="0" alt="GGE" title="GGE" src="http://static.greatgamesexperiment.com/badge/game/valgard/gge400x56.png"></a>

  7. #7

    Showing message on screen for fixed time period

    Thanks Huehnerschaender!!

    I've compiled your code but the message appears when it should but it doesn't go away?? Am I doing something wrong?

    Code:
    procedure TFormGame.BonusLife;
    begin
      with BonusMsg do
      begin
      Text &#58;= 'Bonus life!';
      NeededPoints &#58;= 25000;
      StartTime &#58;=  0;
      Duration&#58;= 5000;
      end;
      if &#40;points >= BonusMsg.NeededPoints&#41; then
    begin
      with BonusMsg do
      begin
        StartTime &#58;= GetTickCount;
        inc&#40;NeededPoints, 25000&#41;;
      end;
    end;
    
    if GetTickCount - BonusMsg.StartTime < BonusMsg.Duration then
      dxFontBonus.TextOut&#40;dxDrawGame.Surface,300,330,BonusMsg.Text&#41;;
    end;
    procedure bonus life is called in my playing statemachine.
    Wake up from the dream and live your life to the full

  8. #8
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Showing message on screen for fixed time period

    I think a easy way would be to set a message string and timer (integer or single). When you reached a certain score, you can set the message to what ever you want and set the timer to x seconds (or x millisecond).
    Next you can render the message if Timer > 0 in the game main render loop. In the update loop (can be same as render loop) you decrease the your timer by the time that is passed until it reaches 0.

    (This is the theory)
    NecroSOFT - End of line -

  9. #9

    Showing message on screen for fixed time period

    You should NOT initialize BonusMsg IN the Bonuslife procedure! You always set the needed points back to 25000 that way which is of course false.

    Init it in gameinit or formcreate or something like that.
    <a href="http://www.greatgamesexperiment.com/game/Valgard/?utm_source=gge&amp;utm_medium=badge_game"><img border="0" alt="GGE" title="GGE" src="http://static.greatgamesexperiment.com/badge/game/valgard/gge400x56.png"></a>

  10. #10

    Showing message on screen for fixed time period

    It works!!! :-) :-) :-) Thanks Huehnerschaender !!!

    The BonusMsg is now initialized in my Starting Playing state and it works like a charm :!: I wasn't thinking, of course the values of BonusMsg must be initialized first!! This is the only procedure in the game, except for the doMoves, the rest is object orientated

    Thanks very much to all you guys, I'm really learning valuable techniques

    All the small detail in my game "Eons" is now sorted and I will post it soon for feedback from you guys :idea:
    Wake up from the dream and live your life to the full

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
  •