|
Title: Vectors? Post by: G.I.L. on September 06, 2009, 02:28:34 PM New Question: I am using the sprite.graphics functions to draw 150 squares and 10 moving lines on one Sprite.It runs at 59-60 fps but then I make one new Sprite and draw and circle that expands on it and the fps drops by ten. Why is this happening and what can I do about it? thx in advance Title: Re: Vectors? Post by: Krux on September 06, 2009, 02:35:26 PM cant say anything about flashdevelop, i never used it, but you can create vectorgraphics with inkscape. It is Free and open Source. But you cant create animations with it.
Title: Re: Vectors? Post by: John Nesky on September 06, 2009, 02:52:32 PM Yes, you're looking for a Graphics object:
http://livedocs.adobe.com/flex/3/langref/flash/display/Graphics.html Graphics objects are only available as a property on Sprites and subclasses of Sprite (such as MovieClip): http://livedocs.adobe.com/flex/3/langref/flash/display/Sprite.html Once you've drawn vector graphics onto a Graphics object, you do not need to ever redraw those vector graphics if you do not intend to animate the graphics, or if the animation can be expressed as rotation, scaling, or other such transformations on the parent Sprite. Title: Re: Vectors? Post by: G.I.L. on September 07, 2009, 04:56:27 PM New Question: I am using the sprite.graphics functions to draw 150 squares and 10 moving lines on one Sprite.It runs at 59-60 fps but then I make one new Sprite and draw and circle that expands on it and the fps drops by ten. Why is this happening and what can I do about it?
thx in advance Title: Re: Vectors? Post by: John Nesky on September 07, 2009, 05:15:25 PM Dunno. You'll probably have to post code and/or a demo.
Random tip 1: semitransparent things render slower than opaque things. Random tip 2: curves render slower than lines. Random tip 3: If you're not adding children to your Sprites, you can use Shapes instead, which are slightly more efficient: http://livedocs.adobe.com/flex/3/langref/flash/display/Shape.html I lied when I said only Sprites had Graphics, Shapes have them too. (But I know of no other examples.) Title: Re: Vectors? Post by: G.I.L. on September 07, 2009, 05:32:25 PM thanks a lot that bumped it up about 3fps. I also remove a couple particles. One more thing. Heres the circle code
Code: mspr.graphics.clear() NOT SHOWN the variable radius continues to increase until it reaches a max range.if (radius>0){ //mspr.graphics.beginFill(0x00FF00,1) mspr.graphics.lineStyle(2, 0x0000FF, ra) mspr.graphics.drawCircle(gfx.x + 11, gfx.y + 11, radius) } mspr.graphics.endFill() when it is at that max range it does not increase. When it is not increasing the fps is at 59-60. But when it increases it slows the game down 10 fps. Do you know why this happens? Title: Re: Vectors? Post by: John Nesky on September 07, 2009, 05:59:48 PM If you're using the debug Flash Player, right click on the animation as it's playing and turn on "Show Redraw Regions". This will show you the "dirty rectangles" that the Flash Player needs to redraw. Assuming a uniform distribution of vector graphic complexity/detail, the render speed will be directly proportional to the area of the screen that is being redrawn. If nothing is moving, nothing is being redrawn and render time will drop to zero and the framerate will jump to the maximum.
Title: Re: Vectors? Post by: G.I.L. on September 07, 2009, 06:06:15 PM Thanks but what should I do about it?
Title: Re: Vectors? Post by: John Nesky on September 07, 2009, 07:01:05 PM IF it turns out that large dirty rectangles are your bottleneck, then either:
1. redesign the animation to reduce dirty rectangle size, or 2. reduce the render complexity by caching stuff to bitmaps. In general, it's faster to draw one bitmap to the screen than it is to render the equivalent vector graphics. 3. Resign yourself to having a lower framerate. For a long time, the default framerate for Flash animations was something like 15 frames per second. http://livedocs.adobe.com/flex/3/langref/flash/display/BitmapData.html#draw() :tiger: Title: Re: Vectors? Post by: Sam on September 09, 2009, 05:03:52 PM Going back to the original question:
Once you make a vector graphic in inkscape and save it as a .svg file, you can use it in your code like so: Code: public class main extends Sprite { [Embed(source = "prettyPicture.svg")] private var myPictureCls:Class; public function main() { var mySprite:Sprite = new myPictureCls(); addChild(mySprite); } } the [Embed...] line followed by the declaration of a variable of type Class is the standard way to embed things without the Flash IDE. Weird little things I have found using this method: Don't use gradients in Inkscape - they don't get imported into your program properly. Don't use alpha values in Inkscape - it does bizarre things when you try to import it. It's not nearly as convenient as using the Flash IDE, but it is easier than trying to use the .graphics stuff to draw complex forms. For the second question, I'm not sure why there would be such a slow down from just drawing a circle every frame. Maybe post your full code here? It certainly sounds like there's something freaky going on somewhere. |