none
Easy Problem! Count down Timer in GraphicsWindow RRS feed

  • Question

  • I am Using the Timer in order to move the shapes in my game, is there anyway I could use the timer to have a countdown from 1:00 Minute to 0:00?

    Here is how the timer is being used in my code so far, can anything be made without changing this?

    Timer.Interval = 50
    
    Timer.Tick = MoveCreature


     


    -Caolan
    Tuesday, November 15, 2011 7:00 PM

Answers

  • Simple example with 60 sec countdown in title bar of GraphicsWindow.

     

    timeRemaining = 60 '1 minute
    Timer.Interval = 50 '50 ms or 20 fps
    Timer.Tick = MoveCreature
    
    Sub MoveCreature
      timeRemaining = timeRemaining - Timer.Interval/1000 ' reduce time remaining at each call
      GraphicsWindow.Title = "Time remaining = "+timeRemaining+" sec" 'Output to title
    EndSub

    Or ring a bell when completed

    timeRemaining = 60 '1 minute
    Timer.Interval = 50 '50 ms or 20 fps
    Timer.Tick = MoveCreature
    
    Sub MoveCreature
      timeRemaining = timeRemaining - Timer.Interval/1000 ' reduce time remaining at each call
      If (timeRemaining < 0) Then
        timeRemaining = 0
        Timer.Pause()
        Sound.PlayBellRing()
      EndIf
      GraphicsWindow.Title = "Time remaining = "+timeRemaining+" sec" 'Output to title
    EndSub


     


    Tuesday, November 15, 2011 7:41 PM
    Moderator

All replies

  • you could keep track of every time MoveCreature is called by adding 1 to a variable, when the variable gets to 1000/20*60 = 3000 then 1 minute is up (60 seconds with 50 ms intervals - 20 per second).  Alternatively you could add 'Timer.Interval/1000' to the variable and when it reaches 60, 1 minute is up.  To count down just subtract 'Timer.Interval/1000' from the variable initially set to 60 say for a countdown from 60 sec.
    Tuesday, November 15, 2011 7:12 PM
    Moderator
  • Thanks, but could you give me an example of that in code form? It's going right over my head at the moment. My brain just isn't working tonight haha. 
    -Caolan
    Tuesday, November 15, 2011 7:33 PM
  • Simple example with 60 sec countdown in title bar of GraphicsWindow.

     

    timeRemaining = 60 '1 minute
    Timer.Interval = 50 '50 ms or 20 fps
    Timer.Tick = MoveCreature
    
    Sub MoveCreature
      timeRemaining = timeRemaining - Timer.Interval/1000 ' reduce time remaining at each call
      GraphicsWindow.Title = "Time remaining = "+timeRemaining+" sec" 'Output to title
    EndSub

    Or ring a bell when completed

    timeRemaining = 60 '1 minute
    Timer.Interval = 50 '50 ms or 20 fps
    Timer.Tick = MoveCreature
    
    Sub MoveCreature
      timeRemaining = timeRemaining - Timer.Interval/1000 ' reduce time remaining at each call
      If (timeRemaining < 0) Then
        timeRemaining = 0
        Timer.Pause()
        Sound.PlayBellRing()
      EndIf
      GraphicsWindow.Title = "Time remaining = "+timeRemaining+" sec" 'Output to title
    EndSub


     


    Tuesday, November 15, 2011 7:41 PM
    Moderator
  • Thank you very much! Much Appreciated!
    -Caolan
    Tuesday, November 15, 2011 7:45 PM