Offsetting text object based on line height

I’m trying to create a sort of scrolling text based on an audio clip and I’m trying to get the top line of the visible text to match with the audio clip.

I have the core logic setup and working fine but I am struggling to find the correct offset amount. I’ve tried using the lineHeight (from textInfo.lineInfo) + lineSpacing, but the offset doesn’t match exactly and after a few lines it’s totally misaligned.

I also tried to simply divide the height of the object by the number of lines and use that value as offset, but that didn’t work either.

Any suggestions on what the correct offset should be?

Thanks!

@Stephan_B hope it’s ok to tag you directly :slight_smile: Afraid this will just get lost within the rest of the posts otherwise :confused:

Thanks!

Using the information contained in the textInfo.lineInfo[ ] is the correct approach.

Line spacing which is from Baseline to Baseline is computed from: first line baseline (typically 0) + lowest descender of line 1 (negative value) - line gap - second line tallest ascender.

Line gap is computed from the primary font asset Line Height - (Ascent line - Descent line).

So the offset from one line to the other, would be lineInfo[0].baseline - lineInfo[1].baseline where these baseline values were computed as per the above explanation.

So depending on how you are scrolling / positioning the text, aligning each line of text to the top of your text contained / view, you would look at the Ascender of each line.

If you are just scrolling and just looking for an offset value, then compare baseline from line to line.

Hope this helps.

That is exactly what I needed! Thank you so much for the quick reply. Incredibly helpful as always Stephan!