Scribe // Waft - Flexible Text Renderers

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
Azzla
Prole
Posts: 43
Joined: Sun Mar 29, 2020 2:23 am

Scribe // Waft - Flexible Text Renderers

Post by Azzla »

I've been using Typo and Floating Text to do text rendering things for previous projects. Both have certain implementation details that don't suit my needs anymore, so I decided to make my own. The primary benefits of Scribe/Waft are:
  • Library instancing
  • Runtime customizability
  • Simplified API
  • Optionality/Flexibility
  • No state leaks
You can grab either of these from my WIP tools-collection repo Stalkpile. :)

Scribe

Code: Select all

Scribe = require('scribe')
Scribe:update(dt)
Scribe:draw()
Scribe:write(<text>, <properties>)
Scribe:scroll(<text>, <properties>)
OtherScribe = Scribe.new() --new library instance.
<text> is any valid Lua string.
<properties> is a table containing (optional) key/value pairs. The default property values are:

Code: Select all

--delay		= 0.1
--linger	= 1
--color		= { 1,1,1,1 }
--x 		= 0
--y 		= 0
--width 	= love.graphics.getWidth()
--justify 	= 'left'
--scale		= 1
--sounds	= false
--font		= love.graphics.getFont()

---- Scroll-Specific ----
--wait		= 1
--speed		= <delay>
--scroll_sounds = false
:scroll takes the same properties as :write, with the additional 3 properties listed. The behavior of :scroll is also identical to :write, but it will "roll-up" (or un-type) each character after the :write is finished.

Most are self-explanatory, but a few properties are worth some explanation:
  • delay is the time between each character rendering.
  • linger is how long the text remains after the final character of the string is rendered.
  • sounds is a valid love audio source or a table containing multiple love audio sources. The sound will play with each new character (excluding spaces) added to the string. If there are multiple sources, it will play one chosen randomly from the table.
Waft

Code: Select all

Waft = require('waft')
Waft:update(dt)
Waft:draw()
Waft:splat(<text>, <properties>)
Waft:set(<property>, <value>)
Waft:nudge(<property>, <value>)
OtherWaft = Waft.new() -- new library instance.
<text> is any valid Lua string.
<properties> is a table containing (optional) key/value pairs, but it is expected that you will want to customize most of them.
:set changes the specified property for all instances currently rendered by Waft.
:nudge adds a value to the specified numeric property of all instances currently rendered by Waft.

The default property values are:

Code: Select all

--duration	= 1,
--color		= { 1,1,1,1 },
--x 		= love.math.random(0, love.graphics.getWidth()),
--y 		= love.math.random(0, love.graphics.getHeight()),
--dx 		= --random value between -100 and 100
--dy 		= --random value between -100 and 100
--rotation	= 0,
--scale		= 1,
--fade		= { _in = 0.5, _out = 1}, --start of the fadeout, end of the fadeout.
--font		= love.graphics.getFont()
--------------------------------------------------------
In addition to the above, :write, :scroll, and :splat all return a handle to the created instance. You can capture it to customize any property at runtime, using the same :set and :nudge syntax. For example:

Code: Select all

local popup_1 = Waft:splat("Hello World")

function love.update(dt)
	Waft:update(dt)
	Waft:nudge('rotation', math.pi * dt) --All popups created by 'Waft' are rotated at runtime
	popup_1:nudge('rotation', math.pi * dt) --Only this popup is rotated at runtime
end
Note that :set and :nudge used on instance handles are just syntax sugar with extra type-safety:

Code: Select all

popup_1:set('x', 100) -- popup_1.props.x = 100
popup_1:nudge('x', 100) -- popup_1.props.x = popup_1.props.x + 100
You must call :update(dt) and :draw() in your love callbacks to see any effect.

You can find the code for the attached gifs on github. More in-depth documentation is being worked on, but honestly the APIs are super simple so it shouldn't be too hard to get them up-and-running.
Attachments
Scribe example.
Scribe example.
xM7vZaeUDd.gif (96.13 KiB) Viewed 8722 times
Waft example.
Waft example.
VSXLBEquGX.gif (717.35 KiB) Viewed 8722 times
libraries: Stalkpile
electronic music stuff: https://soundcloud.com/azzlamusic
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests