This extension class allow you to create an Image display object that is touchable only at the points where alpha is 0 (or higher – by using the threshold parameter).
//First we must create hitArea for a bitmapaData used in Image. var myBitmap:Bitmap = new MyBitmap (); var hit_1:PixelHitArea = new PixelHitArea ( myBitmap, .2); // second arg is sampling for bitmapData //or var hit_2:PixelHitArea = new PixelHitArea ( myBitmap, .5, 'area_name'); //then trace ( PixelHitArea.getHitArea ('area_name') == hit_2 ) // true //Now we can create a PixelImageTouch. var img_1:PixelImageTouch = new PixelImageTouch ( Texture.fromBitmap (myBitmap), hit, 150 ); //last arg is a treshold for alpha channel; var img_2:PixelImageTouch = new PixelImageTouch ( Texture.fromBitmap (myBitmap), PixelHitArea.getHitArea('area_name')); //Additional usage. img_1.hitArea = otherHitArea; //or null, then PixelImageTouch works just like Image, still is touchable but without alpha test //dispose, after that PixelImageTouch works just like an Image hit_1.dispose (); PixelHitArea.disposeHitArea ( PixelHitArea.getHitArea('my_name') ); PixelHitArea.dispose (); //dispose all ares trace (PixelHitArea.getDebugInfo ()) //get size and time needed to create for all hitAreas, size is valid only in debug mode, in normal it equals 0;
You can browse the source code on its https://github.com/krechagames/starling-extensions/tree/master/src/starling/extensions/krecha.
Sorry! I don't now which Bitmap class did you import…… So you have to write down which Bitmap class did you import.
- it is the flash.display.Bitmap; (works great for me, thx!)
dear, what is MyBitmap? can you give example thank you very much!!1
Yes, what is “MyBitmap” please give an example
Hi how to use this with your asset manager ? in order to cache only needed images from one particular Atlas ?
MyBitmap is just a bitmap included in your project with [Embed] metadata.