Scrolling text help
Blitz3D Forums/Blitz3D Beginners Area/Scrolling text help
| ||
For my text adventure, I'm using a sort of 'scrolling' text feature. It goes like this; Write "P" delay 100 Write "r" delay 100 Write "e" delay 100 Write "s" delay 100 Write "s" Now it works fine and all, but the problem is that it's way too time consuming to use for every single text block. is there a way I can simply enter text, and have some commands break it up for me with a delay, or similar to that? Thanks. |
| ||
Have a look at strings and related functions. |
| ||
Yes you could code such a procedure/function by using the string functions http://www.blitzbasic.com/b3ddocs/command_list_2d_cat.php?show=String https://www.google.com/?q=scrolling+text+site:blitzbasic.com/codearcs/ https://www.google.com/?q=scrolling+text+site:blitzbasic.com/ |
| ||
You can use a function like this :Function WriteWithDelay(txt$,interval) For i = 1 To Len(txt) Write Mid(txt,i,1) Delay interval Next End Function and then, call it like that : WriteWithDelay("You just need to call that function to write text with a delay between letters.",100) |
| ||
Alright, I think I've got it. Thanks to everyone for the help! |
| ||
Actually, just one last thing; using a low delay, i.e 25, gives a 'chunky' text output. Instead of fluently placing the letters next to each other with the correct delay, it outputs the text in small groups. I'm assuming I need to incorporate flip somewhere, I presume? |
| ||
You shouldn't use delay at all really since it halts your programs entire execution....using the system clock (millisecs() ) is a better option, or using a 'timer'. eg.....what happens if you want something animation while the text is appearing - with a delay that's not going to happen..... |
| ||
Alright, then how do I incorporate millisecs() into the code? |
| ||
;before the mainloop : StartMs% = millisecs() ;inside the mainloop : TimeMs% = millisecs() - StartMs if( TimeMs >= 100 ) ;do something StartMs% = millisecs() endif |
| ||
a quick example using RemiD's suggestionGraphics 800,600 SetBuffer BackBuffer() TheText$ = "Would you like to play a game ?" inc = 0 StartMs% = MilliSecs() While Not KeyHit(1) TimeMs% = MilliSecs() - StartMs Cls If( TimeMs >= 300 ) And inc <= Len(TheText$) inc = inc + 1 StartMs% = MilliSecs() EndIf Text 10,10, Mid$(TheText$,0,inc) Flip Wend |
| ||
Well... I still get quite a choppy text display even using the code examples above... |
| ||
Oh wait, never mind. It's perfect :P Thanks! |
| ||
Well, not entirely. I've taught myself most of the for and string commands, and I've come up with thisStartMs = 24 CountMs = MilliSecs() words$ = "Stuff" For i = 1 To Len(words$) StartMs = 0 If CountMs > StartMs Then Write Mid$(words$,i,1) EndIf Next My problem is; How can I write text independently like this: WriteWithDelay("You just need to call that function to write text with a delay between letters.",100) And how can I make the StartMs variable to equal zero only at the start of that loop? The code is probably highly inefficient, but to finally have something work after hours of fiddling around would be nice. |
| ||
It seems that the write command gives a chunky display, even with the millisecs timer. But using text like okee works well. Here is another example with a function, i've added optionnal parameters to write the text where you want (x,y) : Graphics 1024,768,32,2 SetBuffer BackBuffer() TextWithDelay("You just need to call that function to write text with a delay between letters.",25,10,50) Function TextWithDelay(txt$,interval,x=0,y=0) startTime = MilliSecs() While i <> Len(txt) If MilliSecs()-startTime >= interval Then i = i + 1:startTime = MilliSecs() Text x,y,Left(txt,i) Flip Wend End Function you NEED "SetBuffer BackBuffer()" in order to flip correctly and have a neat display. |
| ||
Thank you! |