I am using
@ar2rsawseen textwrap class. It is really a good solution. Also there is one more Textwrap2 by
@atilim which is optimized for vey vey long texts. But i am using ar2rsawseen's cause it also supports formats like justify etc.
I had something in mind like this when i started:
@" in the beginning of the lines. And the code will recognize them and format my line according to correspending parameters.
Example inside txt file:
This is a test line.
@This is a test line.
@ line will be green color. But the first line will be black as default.
What i done:
1-To function TextWrap:setText(text) i added some lines of code like this:
@ characters
local line = TextField.new(self.font, part)
print(atchar) --check only
@ signs inside our text
print(i)
line:setTextColor(0xfff450) --set the wanted color for the <a href="https://forum.gideros.rocks/profile/2" rel="nofollow">@2</a> line
else
line:setTextColor(self.textColor) --else default
end |
2-For the ones doesn't want to format the txt file i wrote another function which you can give spesific lines that you want to change colors. So for example if you will give begin=1 and ending=3, 1,2,3 lines will be differnet color in your program.
function TextWrap:setTextColorRow(begin,endind,color)
self.textColor = color
for i = begin, endind do
local sprite = self:getChildAt(i)
sprite:setTextColor(color)
end
end |
So here is an example project.
When i will finish all the class i will post it here again. I posted before finishing because maybe someone else have some other ideas about it and we can work all together.
Comments
I had an idea in mind to combine @atilims performance with mine alignment settings and create new TextWrap, so any additions like this are also welcome, when I'll finally get to this.
Likes: talis
Till that time i will contribute with my ideas and additions i guess.
I am planning to publish the altered version within this week.
Maybe we should somehow take the desired row in some special code brackets like.
some text here
or just more simple
@ special character)
Any idea about it:D
1-I switched to @atilim 's version of Textwrap2 class and added alignment,linespacing,letterspacing,defaultcolor change and special coloring of rows properties.
Here is the example of the init function
text = text to show on screen
areaWidth = textarea width on screen
areaHeight = textarea height on screen
lineSpacing = text's line spacing
letterSpacing = text's letter spacing
align = Supporting "left","right" or "center" by default it is "left" alligned.
font =ttf font to be used
mainColor = text's main color by default black
color1@" signs will be omitted from the text.
@ar2rsawseen maybe you can help me with my problems.
Problems:
@ sign to some long row when the code is splitting the row my color is returning to default color again.
I am attaching my whole project for all forum usage hope it will be usefull to someone.
Likes: gorkem
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
@techdojo you are welcome.
Additions i want to implement soon:
1-It is a simple one but i thought that why this class is not returning the number of lines it is holding.
So i wanna a wrote a function inside returning number of lines.
Possible usage of it:
According to number of lines you want to switch auto scrolling or not.
2-Another idea is to implement event listeners inside the class and control their behavior with boolean parameteres like autoscroll=ture,false or scrollable=true,false
autoscroll= the text is sliding by itself from the screen without user interaction.
scroll=the text can slide with onmove event.
Thanks
It would be swell if there was a TextWrap-like class that could handle new lines (\n etc) as well as different formats (ie change of font or color) inside a line. :-)
It could also be used to make non-games apps
Likes: pie
Also, this could save memory, instead of loading a huge bitmap (>2000px in height), right? On the other hand, if we're talking a few bitmaps, I guess the memory add-on shouldn't be a big issue? /:)
No, you can only save some disc space because texts should be rendered into texture too. Also cached font for texts consumes big amount of memory.
Likes: saeys