Defold-RichText

Released 2.8.0 to fix a bunch of issues reported by @pkeod. I also added experimental support for spine models. Finally it’s now possible to easily assign layers to the generated nodes to reduce draw calls.

spineboy

5 Likes

rt.zip (841.9 KB)

Edit: made slight adjustment

2 Likes

Thanks! I can honestly say I didn’t give my choice of hero and thumbnail image much thought, but I appreciate you sprucing it up!

3 Likes

I think you should rename is Richie Text!

2 Likes

Or something close to “Ritzl”? Like Ritzh Text? :joy:

Also thanks for this @britzl, I love it! Really make it a lot easier to do fun text stuff :smiley:

6 Likes

I’m trying to figure out a way to have a blinking cursor at the end of a truncating text . Any tip on how to solve that?

Essentially you’d have to figure out the position of the last character after each truncate call. Is there way to access the inner text gui component and get width data on the last line perhaps?

Ah, yeah, that’s currently not very simple to achieve. The call to truncate() should probably return the last visible node of the text. Created issue: https://github.com/britzl/defold-richtext/issues/24

3 Likes

Added support for this now. The truncate() function will now return the last visible word. The function will also update the text metrics of truncated nodes. Added an example with a cursor following truncated text as it is revealed.

5 Likes

Suh-weeet!

2 Likes

Speaking of stuff at the end of text. In our tutorial, I have this pulsating arrow indicator at the end of a text bubble indicating that the game expects the user to click to advance:

The problem is that, since it’s so small, sometimes it overflows on its own, which looks bad:

A way to control overflow would be really useful. I’m not really sure how it would be implemented. I don’t really have an API proposal I’m happy with. Maybe a <nobreak>words that don't break</nobreak> tag?

4 Likes

Thank you for the feature request! Added: https://github.com/britzl/defold-richtext/issues/25

5 Likes

I decided to revive the old and deprecated <nobr> HTML tag. It might not be good enough for browsers but it’s damn well good enough for Defold-RichText!

8 Likes

Coming up next, marquee and blink!

5 Likes

Hi All!!

I’m having some trouble with this and I have no idea where to get started. Here are my steps.

I want to make my countdown cooler by having the minutes being larger than the seconds. I want to do this via richtext. Here’s what I’ve done:

  1. Added https://github.com/britzl/defold-richtext/archive/master.zip as a dependency
  2. Did project -> fetch libraries and sychronised
  3. Checked that richtext appears in my project with the jigsaw piece icon
  4. What should the code be? And have I missed anything here?

Here’s my guess for the code so far:

	local minutes = 320
	local seconds = 182
	richtext.create(minutes.."."..<size=2>seconds</size> )

But that’s not right. Any help?

I am getting

/main/guiscript.gui_script:2: attempt to index global ‘richtext’ (a nil value)
stack traceback:

which makes me assume that I haven’t installed the dependency correctly!

Have you required RichText?

Okay, some time later, I have successfully figured out how to “require” a module. That information should probably be on the “working with library projects” page, and it would be helpful if there was just one name for an engine add-on, instead of switching between module/dependency/library.

Next question:
for a normal text node, it’s okay to use (in update)

		local text= (self.minutes.."."..self.seconds)
		local s= gui.get_node("timernode")
		gui.set_text(s, text)

and the node constantly updates itself as the minutes and seconds go down. How can you do this is a rich text node?

You can get all nodes from richtext and update the one you want, but I’d suggest that you delete and recreate the nodes. If it’s not too much text to process it’s not really going to have much effect on performance.

okay, so here is the code I use to generate the rich text node:

	self.minutes = "minutes"
	self.seconds = "seconds"
	local sampletext = self.minutes.."<size=0.7>".."."..self.seconds
	print(sampletext) 
	self.richtextnode = richtext.create(sampletext, "win96", settings)
	pprint(self.richtextnode)

What is the name of the rich text node in that case (or, how do i access it)? gui.get_node(self.richtextnode) doesn’t seem to work and i can’t find anything in the API.

richtext.create() returns a table structire containing data about the words, tags, nodes etc. There’s a bunch of examples in the repo showing how you can use Defold-RichText:

I’d suggest doing something like this:

local text = ("%d<size=0.7>%d"):format(23, 59)
local words, metrics = richtext.create(text, "Roboto-Regular", { position = vmath.vector3(0, 390, 0) })
gui.set_text(words[1].node, "foobar") -- change text of first word
3 Likes

Many thanks Britzl. I am not a fluent user of lua so there’s a lot I’ll have to learn from your examples! But I am confident I can get it sorted now.

1 Like