Typewriter effect and word wrap problem

Get help using Construct 2

Post » Mon Apr 18, 2016 10:26 pm

Message: mikehive can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Heya, I'm using Rex's text typing plugin - http://c2rexplugins.weebly.com/rex_text_typing.html - to apply a typewriter effect to my dialogue boxes. Very nice, I love it! Only problem is that the word wrap on my spritefont object kicks in mid-word sometimes, meaning you see the word start to spell out on the end of one line, only for the whole word to jump to the next line when it overflows. Is there anything that can be done about this?! The effect is so close to being perfect :)
Image



Coming soon on Steam!
B
16
S
9
G
3
Posts: 204
Reputation: 3,466

Post » Wed Apr 20, 2016 7:02 am

Sorry for bump, but I really need help with this :(

Because my spritefont has a fixed character width and always shows the same max characters per line, I was thinking of running some sort of process on the source text to automatically insert 'newline's before sending it to the text type effect. All I basically need to do is find and replace the LAST " " space instance every x characters, Maybe regex or something. But I'm just not smart enough to work it out.
Image



Coming soon on Steam!
B
16
S
9
G
3
Posts: 204
Reputation: 3,466

Post » Wed Apr 20, 2016 9:32 am

Its maybe easyer to format the source of the text ?
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Apr 20, 2016 2:00 pm

That's what I want to do. But I don't want to do it manually - my game has a looooot of text that I edit and re-edit frequently. I don't want to be constantly previewing and adding newlines by hand because honestly, doesn't that sound like something a computer should do for you? :p

The current character limit for my spritefont is 39 characters per line. All I really need to do is find the last instance of a " " space in every chunk of 39 characters and replace it with a newline. I've been trying to work out the logic and so far my best solution is a hideous dog's dinner of events that involves breaking the text into individual variables for lines and running a bunch of mid() and right() and find() and replace() expressions and then reassembling the lines into one string that is then sent to the text typer. I haven't tried this yet so I don't even know if it'll work - it just seems way too disgusting and unwieldly and I was hoping somebody who's good at coding (which I'm not) would be smarter than me and would know what a real programmer-type person would do and would save me from having to make such a monstrosity :p
Image



Coming soon on Steam!
B
16
S
9
G
3
Posts: 204
Reputation: 3,466

Post » Wed Apr 20, 2016 2:47 pm

I think you should format the whole text to a Dictionary. With 3 str variables. WholeText, TempText, NextText.

once > Set NextText to WholeText

While NextText is not ""

Set TempText to NextText
Variable 'place' = 0

For "index" from 39 to 0
if mid(TempText , loopindex("index"), 1) = " " > break loop
> set place to loopindex("index")
add key to dictonary .. key = str(some counter) .. value = left(TempText,place - 1)

Set NextText to right(TempText, len(TempText) - place)
(you might have to place -1 or + 1, not sure)

Store the .jason, could be handy.

Something like that.
Then you have it all handy. Reading from from the dictonary goes like:
the expression : Dictionary.Get(str(some counter))
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Apr 20, 2016 6:16 pm

Iiiinteresting! OK, thanks for your help, I'll put your idea in the melting pot :)
Image



Coming soon on Steam!
B
16
S
9
G
3
Posts: 204
Reputation: 3,466

Post » Fri Apr 22, 2016 9:09 am

Hey, so I ended up doing this a completely different way - I realised I could use tokenat to just split the string up into words and count the characters in each. I gave my spritefont an instance variable called CharsPerLine to keep track of how many max characters to account for per line and then did this (source text is in a variable called textToProcess):

Image

Then you just call the processNewlines() function whenever you want it to do it!

Works a treat, thought I'd share my solution for any future Construct users who have this problem :)

(You don't need to use the areYouTyping boolean on the spritefont, I just have that because it's useful to know when the typing effect is in process)
Image



Coming soon on Steam!
B
16
S
9
G
3
Posts: 204
Reputation: 3,466


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, Nicolas951 and 14 guests