October 28, 2020, 10:41:52 PM

Author Topic: [bb] Smooth Marquee by Rob Farley [ 1+ years ago ]  (Read 1412 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Smooth Marquee by Rob Farley [ 1+ years ago ]
« on: June 29, 2017, 12:28:43 AM »
Title : Smooth Marquee
Author : Rob Farley
Posted : 1+ years ago

Description : The code should make sense.

If you don't have the scroller going right over the edges of the screen you see letters appear and disappear so you may want to mask these nasty bits out with rects or something, however, looks fine full width.

Let me know how you get on.


Code :
Code: BlitzBasic
  1. ;smooth marquee
  2. ; 2003 Rob Farley
  3. ; http://www.mentalillusion.co.uk
  4. ; rob@mentalillusion.co.uk
  5.  
  6. Graphics 640,480
  7.  
  8. message$="Example smooth horizonal scroller using text command, press esc to quit. This works with any size font, however, you may want to mask the edges either by scrolling the entire screen width or by adding a couple of blocks either side after the text command."
  9.  
  10. font=LoadFont("arial.ttf",30,True)
  11. SetFont font
  12.  
  13.  
  14.  
  15.  
  16. SetBuffer BackBuffer()
  17.  
  18. ;width in pixels of the scroll (this is slightly bigger than the screen)
  19. width=680
  20.  
  21. ; create space padding for the beginning and end of message
  22. padding$=""
  23. Repeat
  24.         padding=padding+" "
  25.         Until StringWidth(padding)>=width
  26.  
  27. ; add the padding to be beginning and end of message
  28. message=padding+message+padding
  29.  
  30. ; where you want to put the scroller (right over on the left so you don't get nasty bits at the edges)
  31. xoffset=0
  32. yoffset=240-(StringHeight("A")/2)
  33.  
  34.  
  35.  
  36. a=1
  37.  
  38. Color 255,255,255
  39.  
  40. Repeat
  41.  
  42. ; find the next section of text to display
  43. wid=1
  44. Repeat
  45.         If a+wid>Len(message$) Then a=1 ;loop back at end of message
  46.         display$=Mid$(message$,a,wid)
  47.         wid=wid+1
  48.         Until StringWidth(display)>=width
  49.  
  50. ; find the amount of scroll you need to move it
  51. scroll=StringWidth(Mid$(message$,a,1))
  52.  
  53. ; smoothly move the text
  54. For n=0 To scroll-1
  55. Cls
  56. Text xoffset-n,yoffset,display
  57. Flip
  58. Next
  59.  
  60. ;go to the next letter
  61. a=a+1
  62.  
  63. Until KeyHit(1)


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal