poke1024 / tove2d

Animated vector graphics for LÖVE.
Other
171 stars 8 forks source link

Can Graphics be saved as svg files? #32

Closed fuggla closed 4 years ago

fuggla commented 4 years ago

Is it possible to save Graphics as text/svg? If so, how? I had a look in the docs but couldn't find anything.

Something like this :)

local tove = require "tove"
local myDrawing = tove.newGraphics()
myDrawing:moveTo(100, 100)
myDrawing:lineTo(200, 250)
myDrawing:lineTo(50, 220)
myDrawing:fill()

-- Save my drawing
local svg = myDrawing:save()
love.filesystem.write("myDrawing.svg", svg)
poke1024 commented 4 years ago

For SVG, no, not currently. But there is a Graphics:serialize() function that returns a Lua table that can then be reinstantiated:

x = myGraphics:serialize()
local newInstance = tove.newGraphics(x)

This is used in the editor demo. But I'm not sure how well tested this is. It should basically work.

fuggla commented 4 years ago

Ok, thanks!