
{"id":2140,"date":"2015-04-09T15:12:01","date_gmt":"2015-04-09T14:12:01","guid":{"rendered":"http:\/\/www.matthijskamstra.nl\/blog\/?p=2140"},"modified":"2015-04-09T15:16:32","modified_gmt":"2015-04-09T14:16:32","slug":"using-svg-for-assets-in-openfl","status":"publish","type":"post","link":"https:\/\/www.matthijskamstra.nl\/blog\/2015\/04\/09\/using-svg-for-assets-in-openfl\/","title":{"rendered":"Using svg for assets in Openfl"},"content":{"rendered":"<p>I wanted to use svg for icons in an <strong>Openfl<\/strong> project.<br \/>\nIt&#8217;s not intuitive to do this, so I wrote it down for future use.<\/p>\n<h2>What are svg files?<\/h2>\n<blockquote><p>Scalable Vector Graphics (SVG) is an XML-based vector image format for two-dimensional graphics with support for interactivity and animation. <\/p><\/blockquote>\n<p><em>Source:<\/em> <a href=\"http:\/\/en.wikipedia.org\/wiki\/Scalable_Vector_Graphics\" target=\"_blank\">http:\/\/en.wikipedia.org\/wiki\/Scalable_Vector_Graphics<\/a><\/p>\n<p>Good to remember that they scale awesomely without lost of resolution!<\/p>\n<h2>How to add it to your project<\/h2>\n<p>You can find the svg code on <a href=\"https:\/\/github.com\/openfl\/svg\" target=\"_blank\">github<\/a>.<br \/>\nBut you can install it easier with <strong>haxelib<\/strong><\/p>\n<p>Open your terminal and write:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">haxelib install svg<\/pre>\n<p>To add it to an <strong>OpenFL<\/strong> project, add this to your project file:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;haxelib name=&quot;svg&quot; \/&gt;\r\n<\/pre>\n<h2>Code<\/h2>\n<pre class=\"brush: as3; gutter: true; highlight: [13]; title: ; notranslate\" title=\"\">\r\nimport openfl.Assets;\r\nimport openfl.display.Shape;\r\nimport openfl.display.Sprite;\r\nimport format.SVG;\r\n \r\nclass SVGExample extends Sprite\r\n{\r\n\r\n  public function new()\r\n  {\r\n    var svg : SVG = new SVG(Assets.getText(&quot;assets\/openfl.svg&quot;));\r\n    var shape : Shape  = new Shape();\r\n    svg.render(shape.graphics);\r\n    addChild(shape);\r\n  }\r\n}\r\n<\/pre>\n<p>NICE!!!<br \/>\nBut now the cool part: it scales without losing resolution<\/p>\n<p>Check the highlighted line for the changes,<\/p>\n<pre class=\"brush: as3; gutter: true; highlight: [13]; title: ; notranslate\" title=\"\">\r\nimport openfl.Assets;\r\nimport openfl.display.Shape;\r\nimport openfl.display.Sprite;\r\nimport format.SVG;\r\n \r\nclass SVGExample extends Sprite\r\n{\r\n\r\n  public function new()\r\n  {\r\n    var svg : SVG = new SVG(Assets.getText(&quot;assets\/openfl.svg&quot;));\r\n    var shape : Shape  = new Shape();\r\n    svg.render(shape.graphics,0,0,1000,1000);\r\n    addChild(shape);\r\n  }\r\n}\r\n<\/pre>\n<p>for the curious: <a href=\"https:\/\/github.com\/openfl\/svg\/blob\/master\/format\/SVG.hx\" target=\"_blank\">https:\/\/github.com\/openfl\/svg\/blob\/master\/format\/SVG.hx<\/a><\/p>\n<h2>Sources<\/h2>\n<ul>\n<li>I remembered this <a href=\"https:\/\/gist.github.com\/ambethia\/5124913\" title=\"gist\" target=\"_blank\">gist<\/a>, which explains almost everything.<\/li>\n<li>Get icons here, they are free for download as long as you credit <a href=\"http:\/\/www.flaticon.com\/\" target=\"_blank\">freepik<\/a><\/li>\n<li>Featured image from <a href=\"http:\/\/www.webdesignerdepot.com\/\" target=\"_blank\">webdesignerdepot<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I wanted to use svg for icons in an Openfl project. It&#8217;s not intuitive to do this, so I wrote it down for future use. What are svg files? Scalable Vector Graphics (SVG) is an XML-based vector image format for two-dimensional graphics with support for interactivity and animation. Source: http:\/\/en.wikipedia.org\/wiki\/Scalable_Vector_Graphics Good to remember that they [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":2160,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[360,385],"tags":[412,383,388,163,389,160],"class_list":["post-2140","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-haxe","category-openfl","tag-haxe","tag-openfl","tag-scalable-vector-graphics","tag-shape","tag-svg","tag-vector"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/posts\/2140","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/comments?post=2140"}],"version-history":[{"count":13,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/posts\/2140\/revisions"}],"predecessor-version":[{"id":2163,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/posts\/2140\/revisions\/2163"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/media\/2160"}],"wp:attachment":[{"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/media?parent=2140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/categories?post=2140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/tags?post=2140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}