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
282 stars 89 forks source link

graphicsEx.graphics.postProcess() works strange #133

Closed alexeevilya closed 9 years ago

alexeevilya commented 9 years ago

Hi, guys! I've create an instance of shapeEx, run postProcess() and everything works fine. But when I call that method again after some time - nothing happens. Please, see code below:

public class PathTest extends Sprite
{
    [Embed(source="/assets/strokeTexture.png")]
    private var WhiteBMP:Class;

    private var stroke:ShapeEx;

    private var whiteBMP:Bitmap;
    private var whiteTexture:Texture;
    private var points:Vector.<Number> = new Vector.<Number>();

    private var thickness:Number = 8;
    private var container:Sprite = new Sprite();
    private var endIndex:int;

    public function PathTest()
    {
        addEventListener(Event.ADDED_TO_STAGE, onAdded);
    }

    private function onAdded(e:Event):void
    {
        addChild(container);
        stroke = new ShapeEx();

        container.addChild(stroke);

        whiteBMP = new WhiteBMP();

        whiteTexture = Texture.fromBitmap(whiteBMP, false);

        stroke.graphics.lineMaterial(1, new TextureMaterial(whiteTexture, 0xFF0000));

        runExample();

        Starling.current.nativeStage.addEventListener(MouseEvent.MOUSE_WHEEL, mouseWheelListener);

    }

    private function mouseWheelListener(e:MouseEvent = null):void
    {           
        stroke.graphics.postProcess(0, endIndex, new GraphicsExThicknessData(50, 50), new GraphicsExColorData(0, 0));

        trace('Opps..! No Changes...');
    }

    private function runExample():void
    {
        createPoints();

        drawStroke();
    }

    private function createPoints():void
    {
        points.push(100, 0);
        points.push(100, 100);
        points.push(0, 100);
        points.push(0, 0);
    }

    private function drawStroke():void
    {
        for (var i:int = 0; i < points.length; i += 2)
        {
            stroke.graphics.lineTo(points[i], points[i + 1]);
        }
        endIndex = stroke.graphics.currentLineIndex - 1;

        stroke.graphics.postProcess(0, endIndex, new GraphicsExThicknessData(10, 10));

        container.pivotX = container.width >> 1;
        container.pivotY = container.height >> 1;

        container.x = Starling.current.nativeStage.stageWidth >> 1;
        container.y = Starling.current.nativeStage.stageHeight >> 1;
    }
}

Why? What am I doing wrong? source files here: https://www.dropbox.com/s/b5etj1ni38c8on6/pathTest2.zip?dl=0

Thanks!

IonSwitz commented 9 years ago

This was my fault. The geometry wasn't properly invalidated on the call to invalidate() ;)

A fix has been submitted.

But, speaking of another thing. The call to postProcess returns a boolean. true if it was successful, false if it failed for some reason (such as invalid start and end index, for example). It can be useful to check that return value as well.

alexeevilya commented 9 years ago

Thank you very much! Great!