This should be my last update. Im gonna give up on the word thing, there seems to be no way to get it working. In this version, it reacts to all 4 sides of the screen. Ive also included a little 3d world, so that you can see how to use it. Tell me if you like it, or what can be improved(apart from the word seperating). Enjoy
http://sephiroth7769.tripod.com/sitebuildercontent/sitebuilderpictures/textbox2.bmp
+ Code Snippetrem initial vars
sync on
sync rate 60
autocam off
hide mouse
for xdots=0 to 254
for zdots=0 to 254
g=rnd(20)+100
dot xdots,zdots,rgb(50,g,50)
next zdots
next xdots
GET IMAGE 3,0,0,256,256
rem simple world
make matrix 1,1000,1000,50,50
prepare matrix texture 1,3,1,1
randomize matrix 1,8
update matrix 1
make object sphere 1,50
position object 1,500,50,650
color object 1,rgb(250,100,100)
make object sphere 2,50
make object sphere 3,25
position object 2,450,30,630
position object 3,500,100,670
color object 2,rgb(100,255,100)
color object 3,rgb(100,100,255)
position camera 500,50,500
color backdrop rgb(100,100,200)
rem loads images
create animated sprite 1,"textbox2.bmp",3,3,1
load image "talk.bmp",2,1
sprite 2,0,0,2
hide sprite 2
ink rgb(100,100,100),0
do
if mouseclick()=1 then move camera 3
if mouseclick()=2 then move camera -3
yrotate camera wrapvalue(camera angle y()+mousemovex()/2)
xrotate camera wrapvalue(camera angle x()+mousemovey()/2)
position camera camera position x(),get ground height(1,camera position x(),camera position x())+20,camera position z()
if size<30 then size=30
if object screen x(1)>-50 and object screen x(1)<1024+50 and object screen y(1)>-50 and object screen y(1)<768+50
if object in screen(1)=1 then textbox("The red sphere is talking to you...",object screen x(1),object screen y(1),185)
endif
sync
loop
function textbox(text$,tx,ty,boxwidth)
rem text size, only temporary
textsize=10
rem makes the textbox sprite by cutting an image into 3x3 squares.
spritesizex=sprite width(1)
spritesizey=sprite height(1)
set sprite frame 1,0
segmentsize=sprite width(1)
rem ts the x and y vars, by changing the tx and ty.
ty=ty-segmentsize
tx=tx-segmentsize
if tx>screen width()-30 then tx=screen width()-30
if tx-boxwidth>0 then x=tx-boxwidth+segmentsize
if tx<15 then tx=segmentsize
if tx>x+boxwidth-segmentsize then tx=x+boxwidth-segmentsize
rem gets number of lines relying on the width of the box
lines=1
for lcheck=1 to 50
if len(text$)*textsize<boxwidth*lcheck then lines=lcheck:goto endofcheck
next lcheck
endofcheck:
dim line$(lines)
rem not letting box go over screen
y=ty-lines*segmentsize-10
if y<0
y=0 :ty=y+lines*segmentsize+10
`if y>screen height()-lines*segmentsize-(segmentsize*2) then y=screen height()-(lines*segmentsize)-(segmentsize*2)
else
if ty>screen height()-segmentsize then ty=screen height()-segmentsize
y=ty-lines*segmentsize-10
endif
rem pastes all the frames in their correct positions
set sprite frame 1,0
paste sprite 1,x,y
set sprite frame 1,1
for height=0 to lines
if height>0 and height<lines
set sprite frame 1,3
paste sprite 1,x,y+(height*segmentsize)
endif
for top=1 to boxwidth/segmentsize-1
if height=0
set sprite frame 1,1
paste sprite 1,x+(top*segmentsize),y
if top=boxwidth/segmentsize-1 then set sprite frame 1,2:paste sprite 1,x+((top+1)*segmentsize),y
else
if height<>lines
set sprite frame 1,4
paste sprite 1,x+(top*segmentsize),y+(height*segmentsize)
endif
if height=lines
set sprite frame 1,6
paste sprite 1,x,y+((lines)*segmentsize)
set sprite frame 1,7
paste sprite 1,x+(top*segmentsize),y+((lines)*segmentsize)
endif
if top=boxwidth/segmentsize-1 and height<lines
set sprite frame 1,5
paste sprite 1,x+((boxwidth/segmentsize)*segmentsize),y+(height*segmentsize)
endif
if height=lines and top=boxwidth/segmentsize-1
set sprite frame 1,8
paste sprite 1,x+((boxwidth/segmentsize)*segmentsize),y+((lines)*segmentsize)
endif
endif
next top
next height
set sprite frame 1,0
hide sprite 1
if tx<boxwidth/2
mirror sprite 2
paste sprite 2,tx,ty
mirror sprite 2
else
paste sprite 2,tx,ty
endif
rem puts the right amount of characters into each line.
charsinline=boxwidth/textsize
for processlines=0 to lines
for character=processlines*charsinline to processlines*charsinline+charsinline-1
line$(processlines) = line$(processlines) + mid$(text$,character)
next character
next processlines
rem prints the text on the screen with the lines in the right positions.
for printing=0 to lines
ink rgb(50,50,50),0
text x+10,y+(printing*textsize)+6,line$(printing)
ink rgb(150,150,150),0
text x+10-1,y+(printing*textsize)+6-1,line$(printing)
next printing
ink rgb(100,100,100),0
rem frees some memory by deleting a few things.
undim line$()
endfunction