Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In StrikeDisplay, vectors and images are held as Sprite objects in the AS3 sense - which are represented as draw lists internally, and only drawn/redrawn to the canvas as necessary. When a filter requiring convolution or blurring is applied to one of these Sprites, a unique canvas is generated for that individual Sprite+Filter, which is substituted for the original draw list (temporarily). Same thing that happens if you just cache the sprite as a bitmap. So the procedure in StrikeDisplay to draw a black box, add it to the stage and put a blur and a dropshadow on it is:

var s:Sprite = new Sprite();

s.graphics.beginFill("#000000",1);

s.graphics.drawRect(0,0,100,100);

root.stage.addChild(s);

s.filters = [new BlurFilter(4), new DropShadowFilter(2,2,4,"#000000",.8)]

And that's it. It's now automatically drawn to a hidden canvas, which becomes the only item on the Sprite's draw list, retaining the position and transform properties, parent and event hierarchy of the original Sprite. If you modify the Sprite later, re-filtering and re-caching happens automatically. And if you remove the filters, the original vector draw list is restored and the hidden canvas that fed the filtered version is emptied and deleted.



Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: