svgCreate | Multi Theft Auto: Wiki Skip to content

svgCreate

Client-side
Server-side
Shared

Manual Review Required

Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.


Creates an svg from size (blank document), filepath or raw data.

Note

SVG in MTA is handled by the lunasvg rendering engine - Some features in MTA may not work properly, compared to the browser.

Tip

If you are experiencing poor texture quality or artifacts in the form of black outlines, setting the blend mode to add might help

Important

Before r21155 ( 3157905 ) the provided callback was only fired once after the function had performed its task. This is no longer the case - each SVG can now store a single callback function (optional) which is fired every time the SVG texture has been changed/updated.

Syntax

svg svgCreate ( int width, int height, [, string pathOrRawData, function callback ( element svg )
Required Arguments
  • width: Desired width, preferably power of two (16, 32, 64 etc.), maximum is 4096
  • height: MISSING_PARAM_DESC
  • string pathOrRawData, function callback ( element svg: MISSING_PARAM_DESC

Returns

  • svg: value

This is a basic example of how you can create an SVG from raw data (or path) and draw it with dxDrawImage via onClientRender .

Code Examples

shared

This is a basic example of how you can create an SVG from raw data (or path) and draw it withdxDrawImageviaonClientRender.

-- This could also be a file, with the path provided to svgCreate instead
local rawSvgData = [[
<svg viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg">
<circle cx="250" cy="250" r="250" fill="#0fc0fc" />
</svg>
]]
local myCircleSvg
local function drawCircleSvg()
dxDrawImage(0, 0, 500, 500, myCircleSvg, 0, 0, 0, tocolor(255, 255, 255), false)
end
local function init()
-- Create an SVG containing a circle, using the raw XML data above
myCircleSvg = svgCreate(500, 500, rawSvgData)
addEventHandler("onClientRender", root, drawCircleSvg)
end
addEventHandler("onClientResourceStart", resourceRoot, init)