
Animation is integral to many parts of GUIs, including both the fancy effects when things change used in window managers, and of course games.   The core of any animation system is a scheme for periodically changing the display while still remaining responsive to the user.   This task demonstrates this.



Task

Create a window containing the string "Hello World! " (the trailing space is significant).

Make the text appear to be rotating right by periodically removing one letter from the end of the string and attaching it to the front.

When the user clicks on the (windowed) text, it should reverse its direction.




OpenWindow(0,0,0,500,100,"Hello World!",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
 
text$ = "Hello World! "
direction = 1
 
LoadFont(0,"",60)
ButtonGadget(0,2,2,496,96,text$) : SetGadgetFont(0,FontID(0))
 
Repeat
  event = WaitWindowEvent(50)
  Select event
    Case #PB_Event_Gadget
      If EventGadget() = 0
        direction*-1
      EndIf
    Case #PB_Event_CloseWindow
      End
  EndSelect
 
  If ElapsedMilliseconds()-tick > 400
    offset+direction
    If offset > Len(text$)-1
      offset = 0
    ElseIf offset < 0
      offset = Len(text$)-1
    EndIf
    SetGadgetText(0,Mid(text$,offset+1)+Left(text$,offset))
    tick = ElapsedMilliseconds()
  EndIf
ForEver