News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Displaying one line at a time

Started by geecee, March 03, 2009, 02:35:45 AM

Previous topic - Next topic

geecee

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.

PlayBASIC Code: [Select]
` ------------------------------------------------------
` 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."



Any comments constructive or otherwise appreciated.

Thanks
geecee



Related Topics

 Word Wrap Function

LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)

micky4fun

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 :)

geecee

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
LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)