0
votes

I am doing a magnifying glass effect?

I have a working version. However the performance is not good enough on the tablet.

What i have done so far:

I had a ENTERFRAME event on a mouseDown

So it start capture the screen when the mouse click down, and follow the mouseX and mouseY

It works, but the only problem it keep draw the whole stage rather than maybe (300px * 300px) around the mouseX and mosueY. is there a way i can make the draw area according to your mouseX and mouseY. I guess that would help the performance as well. :)

e.target.removeEventListener(Event.ENTER_FRAME, startCapture);

function startCapture(e:Event):void{
    var glassWidth:uint=80;
    var glassHeight:int=80;
    var curBd:BitmapData;
    var curBmp:Bitmap;
    var posX:int = _parentStage.mouseX - 40;
    var posY:int = _parentStage.mouseY - 40;

    //-------------------------------------------------------------
    //var subArea:Rectangle = new Rectangle(0,0,500,500);
    //var newBmp:Bitmap = new BitmapData(500,500);
    //var cutoutBmp:Bitmap = new Bitmap( newBmp, PixelSnapping.ALWAYS, true );
    //cutoutBmp.bitmapData.draw( jpgSource, new Matrix(1, 0, 0, 1, -357, -341) , null, null, subArea, true );
    //-------------------------------------------------------------

    bd = new BitmapData(1024, 768, true, 0);
    var subArea:Rectangle = new Rectangle(_parentStage.mouseX, _parentStage.mouseY, 500, 500);
   // bd = new BitmapData(500, 500);
   bd.draw(_parentStage.mc_mainContainer);
    // bd.draw(_parentStage.mc_mainContainer);

    curBmp=new Bitmap(new BitmapData(glassWidth,glassHeight), PixelSnapping.ALWAYS);
    curBmp.bitmapData.copyPixels(bd,new Rectangle(posX,posY,_parentStage.mouseX,_parentStage.mouseY),new Point(0,0));
    curBd=curBmp.bitmapData;

    var ma:Matrix = new Matrix(1, 0, 0, 1, -40, -40);
    glass.name = 'glass';
    glass.alpha = 1;
    glass.graphics.clear();
    glass.graphics.beginBitmapFill(curBd, ma);
    glass.graphics.drawCircle(0, 0, 35);
    //glass.graphics.drawCircle(0, 0, 35);
    glass.graphics.endFill();

    //var imageCircle:Bitmap = new _magGlass();
    //trace(_magGlass);
    //glass.addChild(_magGlass);

    if(!_parentStage.contains(glass))_parentStage.addChildAt(glass, _parentStage.numChildren - 2);
    glass.x = _parentStage.mouseX;
    glass.y = _parentStage.mouseY - 75;
}
1
What is bd and why do you draw _parentStage.mc_mainContainer to it?user1080806
@atonparker bd is bitmap and _parentStage.mc_mainContainer is the stage pretty muchBill
In your question you ask why it is drawing the whole stage, could that be the line that is doing that?user1080806

1 Answers

2
votes

Where your performance problem is coming from is where you're creating new bitmaps and bitmapdatas and rectangles on every frame. Instead, just create one or two in the constructor or on click and then reuse them. Since you already have a BitmapData, you can probably just put that on the stage and mask it, rather than using the graphics object in glass. At least pick one approach or the other. Doing both is killing you, performance wise.