Wwwebber's Blog

Actionscript 3: BitMapData–how to Dynamically Apply a filter, scale and then center BitmapData

Posted in bitmapdata, image effects, Uncategorized by wwwebber on February 21, 2010

Basically, if you are wondering how to create a new BitmapData by scaling a display object and also applying a filter and you would like to keep track of the new center of your scaled bitmapdata …this example is for you.


I was working on a new game for my online math games site and I wanted to be able to create a new BitmapData that was a scaled down version of a library item. This in itself is easy but it required a bit of extra to work to also be able to scale the display object dynamically as well as dynamically apply a filter , and all the while keep track of the center of the ‘real object’ (ie the radius of a original circular meteor). Knowing the true center of the bitmapdata as well as the radius of the ‘real’ object (ie not counting the filter) is necessary for doing collision testing in the math game.

I have attached a flash cs3 version of the file whose demo you can see here and download the cs3 file here. As an aside, I hate using timeline code but I wanted to provide this example in a single file…so I put all the code in the main time line. The code does all of the work and places a red dot at the calculated center of the bitmap. This sort of stuff is useful in games that requiring blitting aka 8bitrocket.com style

Pseudocde
1) create instance of library item (in my case a meteor)
2) Scale down or up the item
3) apply filter around item
4) create a new bitmapdata based on the size of the scaled meteor and the size of the filter (both dynamic)
5) keep track of the ‘actual’ radius of the scaled meteor (ie sans the filter)

Advertisements

One Response

Subscribe to comments with RSS.

  1. […] bitmapdata, image effects by wwwebber on February 21, 2010 Following up on my last post on how to dynamically, scale and apply filters to display objects and then copy these into bitmapdatas , I wanted to implement the […]


Comments are closed.

%d bloggers like this: