Main Menu

Text Functions

Started by kevin, January 24, 2011, 05:09:09 PM

Previous topic - Next topic

kevin

  Text Functions

    Here's a couple of function to draw text, the first supports Left/Right justified text and second draws shadowed centered text.    



PlayBASIC Code: [Select]
      loadfont "arial",1,32

Ypos=100
ypos2=ypos+getFontHeight(1)
boxc 100,Ypos,700,Ypos2,true,$223344

AlignedText(100,Ypos,"Left Hello")
AlignedText(700,Ypos,"Right Hello",1)

Shadowedtext(400,Ypos,"Shadowed text",$ff0009)


Sync
waitkey
end




psub AlignedText(xpos,ypos,s$,Rightalignx=false)
if RightAlignX
xpos-=GetTextWidth(s$)
endif
text Xpos,Ypos,s$
Endpsub


psub Shadowedtext(xpos,ypos,s$,colour,centerx=true,centerY=false)
oldink=getink()

if CenterX
Xpos-=(Gettextwidth(s$)/2)
endif

if CenterY
Ypos-=(GettextHeight(s$)/2)
endif

ink $ff222222
text xpos-1,ypos+1,s$
ink Colour
text xpos,ypos,s$

ink oldink
endpsub






kevin

#1
    Text Reveal - Reveal TEXT


      This function draws a message with  foreground and background colour.  The amount of foreground is variable and can slide from the left to the right.  Allowing you to reveal the message.   It's a effect used in video productions where the on screen text tracks along with the voice over.



   



PlayBASIC Code: [Select]
      loadfont  "arial new",2,108
setfont 2

// get the height of the current font
Th=GetTextHeight("!")

do
cls

// get the low bits of the timer
TimePast=timer() and $3ff

// Convert the current millisecond into a scaler
Scale#=float(TimePast)/1024


scrolly=th*Scale# ;mod(ScrollY+1,Th)


// Apply cossine to the Scale to make it's motion
// look more round
Scale#= 0.5+ cos(Scale#*360)*0.5




// Set the scroll offset from the current millisecond




//
for ylp=-th to getsurfaceheight()+th step th
RevealText(150,ylp-ScrollY,"Hello World",rgb(0,0,255),rgb(255,255,255),Scale#)
next

sync
loop spacekey()










Function RevealText(Xpos,Ypos,Message$,Colour1,Colour2, Scale#)

oldink=getink()

ink colour1
text Xpos,Ypos,Message$


Width=GetTextWidth(Message$)
Xpos2=Xpos+Width*ClipRange#(Scale#,0,1)
screenviewport 0,0,Xpos2,GetSurfaceHeight()

ink colour2
text xpos,ypos,Message$

ink oldInk
screenviewport 0,0,getsurfacewidth(),GetSurfaceHeight()

EndFunction