Author Topic: SVG Support  (Read 1799 times)

Black Drazon

  • Guest
SVG Support
« on: Thu, Sep 10, 2009 »
Is there any way to use SVG files with Flixel?  Flex can support them but I'm not sure if it would be possible to use them with flixel without substantive hacking.

Merve

  • Guest
Re: SVG Support
« Reply #1 on: Thu, Sep 10, 2009 »
Having a poke around it appears very easy to do
Here's the code:
Code: [Select]
                [Embed(source='library/star.svg')]
private var crosshairClass:Class;
private var crosshair:Sprite = new crosshairClass ();
Pulled from here: http://www.streamhead.com/how-to-use-vector-graphics-in-flashdevelop-svg-in-flash/

Titch

  • Contributor
  • ****
  • Posts: 270
  • Karma: +0/-0
  • Thing with the guy in the place.
    • View Profile
Re: SVG Support
« Reply #2 on: Fri, Sep 11, 2009 »
I think you would probably have to use .draw() to render the SVG into a bitmap data on account of Flixel being a blit based engine.
Free cake whippings every day at #flixel on irc.freenode.net.

Black Drazon

  • Guest
Re: SVG Support
« Reply #3 on: Fri, Sep 11, 2009 »
I'm not having any luck with Merve's method so I'm going to have to as Titch to rephrase: what do you mean by draw()?  I assume you mean BitmapData's draw function, but I'm not having any luck with it either.  Here's what I have, after embedding the svg file as "svgStar" just to be more obvious:

Code: [Select]
var starSprite:Sprite = new svgStar() as Sprite;
var bitmapData:BitmapData = new BitmapData(starSprite.width, starSprite.height, true, 0xFFFFFFFF);
bitmapData.draw(starSprite);
var bitmap:Bitmap = new Bitmap(bitmapData);

I then convert the Bitmap back to "Class" since that's what FlxSprite wants, so that could easily be the problem, but I'm not sure how to do it any other way without hacking FlxSprite.

The error comes up during FlxG.createBitmap and is phrased "Invalid BitmapData".  The problem may very well be the conversion to Sprite as that was what wasn't working with Merve's method, but I'll wait for other people's opinions.
« Last Edit: Fri, Sep 11, 2009 by Black Drazon »