UnderwareDESIGN

PlayBASIC => Resources => Source Codes => Topic started by: geecee on March 03, 2009, 02:35:45 AM

Title: Displaying one line at a time
Post by: geecee on March 03, 2009, 02:35:45 AM
Here's a short programme I've written ...... nothing spectacular ...... just making use of what I have learned so far in PB.

The programme demonstrates how to write text to the screen ... one line at a time.

In this particular example, the message has 18 lines, including blanks, and is positioned on the screen according to a random 1 of 3 selections ...
1 equals left aligned, 2 equals centered and 3 equals right aligned.

The speed at which the lines are written to the screen is determined by the 'setfps' value.

[pbcode]
` ------------------------------------------------------
`                  ONE LINE AT A TIME
` This programme demonstrates how to write text to the
`             screen ... one line at a time
`                ***********************
`                    Author: geecee
`        Written for Dark Basic in December 2006
`        Rewritten for Play Basic in March 2009
`                ***********************
`-------------------------------------------------------

` Start of programme
start:

` Set text style and size and determine text height
loadfont "arial",1,20,0
th=gettextheight("arial")

` Set ink colour and draw a box to hide previous text at the location
ink rgb(0,0,0)
box 0,0,799,599,1

` A short wait before proceeding
sync
wait 1000

` Restore data statements
restore FindData( "statements:",0,0)+1

` This command will hide the mouse pointer
Mouse off

` Declare array/s
dim message$(30)

` Read in data statements
for a=1 to 18
  s$=readdata$()
  message$(a)=s$
next a

` Set down coordinate
down=51

` Set ink colour
ink rgb(255,217,128)

` Set writing speed  
setfps 3

` Set random number for display
c=rnd(2)+1

` Write message lines to screen. If the random selection c
` equals 1 then the text is left aligned. If the random
` selection c equals 2 then the text is centered. if the
` random selection c equals 3 then the text is right aligned
for b=1 to 18
  tw=gettextwidth(message$(b))
  if c=1 then d=400
  if c=2 then d=400-tw/2
  if c=3 then d=400-tw
  across=d
  down=down+th*1
  text across,down,message$(b)
  sync     
next

` Define message$ and write to screen
message$="Press any key to rerun"
centertext 400,500,message$

` Wait for user keypress and ......
sync
waitkey

` ..... return to start
gosub start

` Data statements
data "statements:"
data "This programme demonstrates how to write text to", "the screen ... one line at a time."
data "", "Author :  geecee    -     March 2009"
data "", "In this particular example, the message has 18 lines,"
data "including blanks, and is positioned on the screen", "according to a random 1 of 3 selections ..."
data "1 equals left aligned, 2 equals centered and 3"
data "equals right aligned."
data "", "The speed at which the lines are written to the"
data "screen is determined by the 'setfps' value ... the", "higher the number the faster the speed."
data "", "Experiment with different font typefaces and sizes,"
data "across and down values, different number of", "message lines, different 'setfps' values etc."
[/pbcode]

Any comments constructive or otherwise appreciated.

Thanks
geecee



Related Topics

 Word Wrap Function (http://www.underwaredesign.com/forums/index.php?topic=2888.0)

Title: Re: A short programme ...... One line at a time
Post by: micky4fun on March 03, 2009, 06:25:27 AM
hi geecee ,,

thanks for code , this will could come in handy for later projects of mine , the data and restore command nicely done and easy to follow whats happing ,, i will keep this in my playbasic code folder ..

thanks
mick :)
Title: Re: Displaying one line at a time
Post by: geecee on March 03, 2009, 05:06:33 PM
To kevin

Thanks for your edit ...... I copied and pasted the example, and ran "as is".  Then made a few changes and ran again ...... Good example.

Your help as always is much appreciated.

To micky4fun

You're welcome ...... Glad I could be of assistance.

geecee