Gradually Displayed Text

BlitzPlus Forums/BlitzPlus Beginners Area/Gradually Displayed Text

InvincibleWall(Posted 2010) [#1]
in some games the storyline/tutorials are slowly "Typed" onto the screen as the person talks

so instead of drawing "Hello, My name is Bob!" it will draw

"Hello"

then...

"Hello, My"

then...

"Hello, My Name"

and so on...

to do this would it be best to create two strings

String1$ = ""                        ;to be displayed
String2$ = "Hello, My name is Bob"   ;full text 


and use Left to move the full text to the displayed text like this?

for x = 1 to Len(String2)
  String1 = Left(String2,x)
  cls
  Text 12,12,String1
  flip
next


or is there a better way to do this?

thank you in advance


CS_TBL(Posted 2010) [#2]
You're filling String1 with Left(String2), and then printing String1?

Why not just:

Text 12,12,Left(String2,x)

directly? :P


xlsior(Posted 2010) [#3]
That's pretty much it...

You can also do individual characters with mid$ instead of re-copying the entire string with left$, but any benefits would be negligible...

But also keep the length of the string in mind (under blitzmax you can use textwidth and TextHeight to figure out the size of a string in pixels, don't know about blitzplus). That way you know when your string1$ is getting too wide for the screen, and when that happens use a second line variable to be printed -- otherwise you'll just end up with a single very long line that'll run off the screen when it gets too long.

(Or instead of using hardcoded strings, use and array of strings so you can dynamically adjust to the number of lines without painting yourself in a corner)


InvincibleWall(Posted 2010) [#4]
cool thanks

CS_TBL
yah that would make it a lot simpler.... can't believe i didn't think of that in the first place

xlsior
I think there is a very similar function to TextWidth() in blitzplus might be StringWidth() or something, only thing is -- is there a character that will add a new line to the actual text or do I need to use multiple Text() calls?


xlsior(Posted 2010) [#5]
You'll need multiple text calls, hence the need the split up the string...


InvincibleWall(Posted 2010) [#6]
okay yah thats what I thought

thank you again =D


Andy_A(Posted 2010) [#7]
Or you could use a function out of the archives like this:



edit: made a longer string to wrap to a new line