Can I import svg into Gideros?

62 views Asked by At

Ok I will admit to being a noob with Gideros. I am trying to import an svg file. I followed the same procedure as you would do for a png file, that is create a texture using:

myTexture = Texture.new("orangeSquare.svg")

orangeSquare = Bitmap.new(myTexture)

stage:addChild(orangeSquare)

Unsurprisingly it doesn't work (output gives orangeSquare.svg: Error while reading image file. and program does not run) as it is not a bitmap file. Is there an alternative to import svg files? It is probably a very simple solution but I have been searching for some time without an answer. I am considering giving up on Gideros if I don't find an answer to what should be a simple problem.

1

There are 1 answers

1
mourad On

You can not import the svg directly, you need to pass the svg data:

--Banana shape, SVG path format
local banana = "M8.64,223.948c0,0,143.468,3.431,185.777-181.808c2.673-11.702-1.23-20.154,1.316-33.146h16.287c0,0-3.14,17.248,1.095,30.848c21.392,68.692-4.179,242.343-204.227,196.59L8.64,223.948z"
p=Path2D.new()
p:setSvgPath(banana) --Set the path from a SVG path description
p:setLineThickness(5) -- Outline width
p:setFillColor(0xFFFF80,0.7) --Fill color
p:setLineColor(0x404000) --Line color
p:setAnchorPosition(100,100)
stage:addChild(p)

You can find more info on their wiki: https://wiki.giderosmobile.com/index.php?search=svg&title=Special%3ASearch&go=Go&fulltext=1

They also have it as a sample project when you open gideros studio.