TGC Codebase Backup



Scrolling Text Example by Anonymous Coder

24th Feb 2006 14:41
Summary

Simple upward scrolling of lines as new lines are added.



Description

This is a nifty little example of how to shift lines of text upward every time a new line is added to the bottom.
It's really just an illusion, though. What is really happening is that the text box erases and the old lines + new line are reprinted with the exception of the topmost line which appears to "scroll" off into nowhere.
If anyone knows of a better way to do this (or mimic windows scroll bars), I'd love to know.

- Jeff Scanga (Scanga@AOL.COM)



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    
` Scrolling Text Example
` By Jeff Scanga   2-24-2006
` Scanga@AOL.com

` This defines the message variable that will contain different lines of text.
DIM Msg$(20)

CLS

`Draws a little text box that looks sort of like the National Geographic Logo
INK RGB(255,255,159),0
BOX 150,100,300,110
BOX 150,290,300,300
BOX 150,100,160,300
BOX 290,100,300,300
INK RGB(252,82,146),0

` This is just my lazy way of creating 20 different sample lines of text.
FOR X = 1 TO 20
   Msg$(X) = "Line " + STR$(X)
NEXT X

TEXT 175,305,"<Click the Mouse Button to Proceed>"

SYNC ON
` This first loop sets up the logic to print 20 lines of text within that box, and scrolls them when necessary.
FOR Y = 1 TO 20
   ` The first 12 lines don't need scrolling.  Can you Guess why?
   ` You guessed it!  The box is big enough to contain the first 12 lines.
   IF Y < 13 THEN TEXT 161,96+(Y*15),Msg$(Y)
   ` Now, we've reached line 12 so now we have to scroll up.  This next Loop is for doing that.
   IF Y > 12
      ` Here's the dirty trick:  I don't really know how to scroll, so I'm faking it.
      ` I first erase the entire box...
      GOSUB ERASE
      ` ...Then I set up another loop to re-print the 12 lines except that this time
      ` I only print from Line 2 to Line 13.
      FOR Z = 1 TO 12
         TEXT 161,96+(Z*15),Msg$((Y-12)+Z)
      NEXT Z
      ` As the program goes back to the beginning of the loop, it will come to this nested loop
      ` again, erase the box again, and then reprint from Line 3 to Line 14 and so on until it
      ` finishes at Line 20.
   ENDIF
   SUSPEND FOR MOUSE
NEXT Y
SYNC OFF
`Disable the "SYNC ON" and "SYNC OFF" commands to see what's REALLY happening.
`It will be obvious that I'm cheating and not really scrolling, but erasing and reprinting.


` This is just a simple sub-routine to erase our box.
Erase:
INK 0,0
BOX 161,111,289,289
INK RGB(252,82,146),0
RETURN

REMSTART
   Now - what I would like to know is if there is a better way to do scrolling.
   This seems to be some rather tedious code, so I'm curious if someone has a better technique.
   Please write me at Scanga@aol.com if you have.
   I would also like to know how I might accomplish smooth scrolling with text.
   True smooth scrolling would advance the lines of text a couple of pixels at a time.
   This would mean that as a line advances it would get cut off by the top of the frame and only
   a portion of that line would be visible.  Perhaps I have to convert the text to an image.
   Somehow, that doesn't seem to be the way to go.

   Anyway,
   Thanks for trying out my code!

   - Jeff Scanga
REMEND


































` Nothing to see here.  Please disperse.