Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I managed to do it after all, and I already wrote my class for collision detections,/collisions angle and other extras.</p> <p>The most confusing process is maybe to align the bitmaps correctly for comparing. When whe draw() a movieclip into a a BitmapData, if we addChild() the corresponding Bitmap we can see that part of it is not visible. it appears to be drawn from the center to right and down only, leaving the top and left parts away from beeing drawn. The solution is giving a transform matrix in the second argument of the draw method that aligns the bitmap and makes it all be drawn.</p> <p>this is an example of a function in my class to create a bitmap for comparing:</p> <pre><code> static public function createAlignedBitmap(mc: MovieClip, mc_rect: Rectangle): BitmapData{ var mc_offset: Matrix; var mc_bmd: BitmapData; mc_offset = mc.transform.matrix; mc_offset.tx = mc.x - mc_rect.x; mc_offset.ty = mc.y - mc_rect.y; mc_bmd = new BitmapData(mc_rect.width, mc_rect.height, true, 0); mc_bmd.draw(mc, mc_offset); return mc_bmd; } </code></pre> <p>in order to use it, if you are on the timeline, you do:</p> <pre><code>className.createAlignedBitmap(myMovieClip, myMovieClip.getBounds(this)) </code></pre> <p>Notice the use of getBounds which return the rectangle in which the movie clip is embedded. This allows the calculation of the offset matrix.</p> <p>This method is quite similar to the on shown here <a href="http://www.mikechambers.com/blog/2009/06/24/using-bitmapdata-hittest-for-collision-detection/" rel="nofollow noreferrer">http://www.mikechambers.com/blog/2009/06/24/using-bitmapdata-hittest-for-collision-detection/</a></p> <p>By the ways, if this is an interesting matter for you, check my other question which I'll post in a few moments.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload