StarlingGraphics / Starling-Extension-Graphics

flash.display.Graphics style extension for the Starling Flash GPU rendering framework
https://github.com/StarlingGraphics/Starling-Extension-Graphics/wiki
MIT License
285 stars 88 forks source link

Adding drawPath and drawGraphicsData to Graphics #66

Open IonSwitz opened 10 years ago

IonSwitz commented 10 years ago

I spent some time tonight to start implementing the drawPath() and drawGraphicsData() APIs from flash.display.Graphics

I got some rudimentary things running, allowing for code like:

        var v:Vector.<IGraphicsData> = new Vector.<IGraphicsData>();
        v.push(new GraphicsLine(1, 0xFFFFFF, 0.4));
        v.push(new GraphicsMaterialFill(someMaterial));
        v.push(new GraphicsPath(Vector.<int>([1, 2, 2, 2, 2, 2]), Vector.<Number>([66,  10,  23, 127, 122, 50,  10, 50, 109, 127, 66, 10])));
        v.push(new GraphicsEndFill());
        v.push(new GraphicsTextureFill(Texture.fromBitmap( new GlowTiledBMP(), false )));
        v.push(new GraphicsPath(Vector.<int>([1, 2, 2, 2, 2, 2]), Vector.<Number>([366, 10, 323, 127, 422, 50, 310, 50, 409, 127, 366, 10])));
        v.push(new GraphicsEndFill());

        var shape:Shape = new Shape();
        shape.graphics.drawGraphicsData(v);
        addChild(shape);

and I have also added support for the GraphicsEx API, adding a GraphicsNaturalSpline class. It behaves a bit differently than the other primitives, so I didn't want to build it into the GraphicsPath class, but it can be added by using a ShapeEx instead of a Shape and pushing new GraphicsNaturalSpline objects into the vector.

Let me know what you think.

IonSwitz commented 10 years ago

This has now been fully committed to the StarlingGraphics master fork. Still not available in the SWC.

IonSwitz commented 10 years ago

I am trying to take this one step further, implementing as good support as I can for the

flash.display.Shape.readGraphicsData API to allow for code like:

starlingShapeEx.graphics.drawGraphicsData(flashShape.graphics.readGraphicsData());

I want to keep the drawGraphicsData API in the ShapeEX class, as it requires the import of flash.display-classes, something that previously wasn't needed to use the starling.display.Shape API.

If @jonathanrpace would care to comment before I continue, I'd be very happy :)

IonSwitz commented 10 years ago

Clean up has been committed to Master. See https://github.com/StarlingGraphics/Starling-Extension-Graphics/issues/79