Home

Awesome

svglover

A pure lua library to import and display simple SVGs in LÖVE.

Tested up to love-11.3 (Mysterious Mysteries).

Note that because it is specifically written for LÖVE, it is probably not useful for other Lua environments.

If you really want to squash your SVGs, try running them through SVGO and/or gzipping them.

The latest code can always be found at Github.

Alternative SVG libraries

News

Features

<img src="screenshot.png" alt="Demo screenshot" />

Why?

Usage

First import the library with require

svglover = require('svglover')

You should normally load your SVGs straight away in the love.load() function to prevent duplicate reads. The syntax for doing this is as follows:

vector_image = svglover.load('some.svg')

You then specify where you want them displayed using:

svglover.display(vector_image,topleft_x,topleft_y,width,height,completely_fill_region,border_color,border_width,zoom)

... where completely_fill_region, border_color, border_width and zoom are optional.

Finally, you should add the svglover.draw() call to the end of your love.draw() function.

A complete example:

function love.load()
    vector_image = svglover.load('some.svg')
    svglover.display(vector_image,100,100,100,100,true,{255,0,0,255},1,1)
end

function love.draw()
    -- draw any scheduled SVGs
    svglover.draw()
end

Development

Feel free to hack, fork, create issues, or send pull requests. It should be possible and not too difficult to add advanced features like text and post-draw handles for dynamic manipuplation of the resulting images to support things like transitions. However, I am personally happy with the existing functionality and will not be adding features in the near future.

Motivation

I wanted to place SVG vector images in a roguelike game I was making, Zomia, but there was no pre-existing library. I first built a proof of concept in perl, svg2love, but then wanted to load files direct from SVG in Lua instead of an intermediate format.

This is my first Lua library, so it probably ignores many best practices.