Discuss Scratch

TheStickUniverse
Scratcher
37 posts

How to make a custom text engine?

I'm making a Deltarune fangame and for it I need to make a custom text engine, for the text during the player's turn in battle as well as for the enemies speaking during their turn. I have the font I need for this and can make the images I need, but I'm unsure how to code one because I've never done it before. Can anyone help me with this? (I'm using the Turbowarp mod.)
kattcrazy
Scratcher
100+ posts

How to make a custom text engine?

I'm trying to make a Notes project too! To me, its really hard, coz u need to get the spacing, etc, right…
cIoudyness
Scratcher
500+ posts

How to make a custom text engine?

kattcrazy wrote:

I'm trying to make a Notes project too! To me, its really hard, coz u need to get the spacing, etc, right…
that’s really not helpful. try to only post in hws when you have a meaningful contribution to a topic

here’s the wiki article for this: https://en.scratch-wiki.info/wiki/Text_Rendering
kattcrazy
Scratcher
100+ posts

How to make a custom text engine?

cIoudyness wrote:

kattcrazy wrote:

I'm trying to make a Notes project too! To me, its really hard, coz u need to get the spacing, etc, right…
that’s really not helpful. try to only post in hws when you have a meaningful contribution to a topic

here’s the wiki article for this: https://en.scratch-wiki.info/wiki/Text_Rendering


S-sorry I'm just trying to be active in the forums and it's encouraging to me when anyone responds on my topics…
B123code
Scratcher
5 posts

How to make a custom text engine?

This project by me has a custom text engine: https://scratch.mit.edu/projects/713456990/ feel free to look inside just pls mention me in the project.
cIoudyness
Scratcher
500+ posts

How to make a custom text engine?

kattcrazy wrote:

cIoudyness wrote:

kattcrazy wrote:

I'm trying to make a Notes project too! To me, its really hard, coz u need to get the spacing, etc, right…
that’s really not helpful. try to only post in hws when you have a meaningful contribution to a topic

here’s the wiki article for this: https://en.scratch-wiki.info/wiki/Text_Rendering


S-sorry I'm just trying to be active in the forums and it's encouraging to me when anyone responds on my topics…
you’re fine D: it’s just generally happier for someone to log on and go “oh someone gave me help!” than “oh someone else has this problem” and that’s what this forum is all about

when in doubt try and find a wiki article, youtube tutorial or some scratch project on the topic. or perhaps try and give some advice/insight “have you tried using clones and setting their local volume to 0 to stop their song, then creating another clone for another song?”
Spentine
Scratcher
1000+ posts

How to make a custom text engine?

First, name all the characters its character, but before that, add an underscore.

example:
a becomes “_a”
b becomes “_b”
1 becomes “_1”
) becomes “_)”
etc.

Have a list that stores all the widths of the characters. Look inside the stamp text engine sprite and look for the dimensions of each text character. A lowercase L would get something like 5x30 or something. You store all the characters' dimensions in order to have proper spacing.

Find the average height of a character and remember that number.

Now after you've done that, create a custom block / function that will take text, x, y, and size as input.

now write this code

define print text (text) (x) (y) (size)
go to x: (x) y: (y)
set [index v] to (0)
set size to ((size) / [28]) // replace 28 with the average height of a character
repeat (length of (text))
change [index v] by (1)
switch costume to (join [_] (letter (index) of (text))
change x by ((item (index) of [lengths v]) * ((size) / [100])) // make this value higher or lower to what you like
stamp // or create a clone but that's bad
end

volia you're done i guess i didn't test it yet

Last edited by Spentine (July 25, 2022 00:46:26)

cIoudyness
Scratcher
500+ posts

How to make a custom text engine?

going to steal the above code a little bit (or perhaps ‘sample’ from it):
most of the costumes and length and width should be setup the same way. one suggestion is to store the letter widths in the list slightly higher than their actual amounts - maybe add one pixel - so that the text isn’t all squished together

tiny fix + a little improvement suggested.
repeat (length of (text ::custom))
change [i v] by (1)
if <(letter (i) of (text::custom)) = ( )> then // to detect spaces
change x by (5)
check new line (text::custom)
if <(return) = [new line]> then
go to x: (x::custom) y: ((y position) - (28)) // replace 28 with something larger than your letter height like 40 for line spacing
replace occurrences of 28 with your maximum letter height. ::#000000
end
else
switch costume to (join [_] (letter (i) of (text::custom)))
stamp
find width of letter (i)
change x by (return)
end
end

define find width of letter (input)
set [return v] to ((item (item # of (letter (i) of (text::custom)) in [lengths v]::list) of [lengths v]) * ((size::custom)/(100)))

define check new line (text)
set [count v] to (i)
set [string v] to ( ) // the empty value
repeat until <(count) = [done]>
change [count v] by (1) // this should be right because this code runs when we’re scanning a space right?
if <(letter (count) of (text)) = ( )> then //check for a space
set [count v] to [done]
else
set [string v] to (join (string)(letter (count) of (text)))
end
end
set [count v] to (0)
set [next word width v] to (0)
repeat (length of (string))
change [count v] by (1)
find width of letter (letter (count) of (string))
change [next word width v] by (return)
end
if <((x position) + (next word width)) > (220)> then
set [return v] to [new line]
end
i seem to have went a little overkill. checking for new lines isn’t necessary but seems nice to avoid text spilling off the edge (plus I’ve wanted to code something like this for a while)

Last edited by cIoudyness (July 25, 2022 02:09:48)

Powered by DjangoBB