Let’s say I have a Text object of width 800. Now let’s say that I want to append text to that object at runtime. Let’s also say that my content would be composed of a list of " " lines.
How would I write the names at the left side of the text object and the scores at the right side? (filling the middle with dots or spaces, for example). How do I know how much spaces should I insert in order to achieve a perfect align?
To set the text of the text object, I believe it’s .text = ;
Double check the API to make sure this is right.
If you want them all aligned what you could do is, for the list of lines check how many characters are in them and then use some basic math to figure out how you want it aligned. After you figured that out, loop through each of the lines and add spaces where needed based on the align calculation.
- Alignment is off
- Loop through the two lines.
- See that ‘Health:’ is 7 characters long before the space; Can also use the ‘:’ as a marker instead of the space
- See that ‘Mana:’ is 5 characters long before the space; Can also use the ‘:’ as a marker instead of the space
- Store max character somewhere.
- Loop through the lines again
- Notice that 7-5 is 2, so the Mana line needs two spaces. Add two spaces in the front
This is a basic example but you get the point?
I would look at having one text object for the name list that is aligned to the left of the parent object, and another text object for the score that is aligned to the right of the parent. Then through your script you can assign the variables needed, like so:
namelist.text = Name1 + "
" + Name2 + "
" + Name3; //For as many names needed
scorelist,.text = score1 + "
" + score2 + "
" + score3; //Again for as many score fields needed
Good luck, hope this helps