发新话题
打印

[分享] 像素级的碰撞检测

本帖已经被作者加入个人空间

像素级的碰撞检测

以前就有网友问到,今天研究了一下,比以前的做法好多了!效率高!
以前的做法:
http://space.flash8.net/space/?284926/action_viewspace_itemid_372562.html
现在:
基本思路:
将要检测的MC转化为BitmapData,然后用其方法hitTest:
as:
import flash.display.BitmapData;
import flash.geom.Point;
var bmp:BitmapData = new BitmapData(Stage.width, Stage.height, true, 0x00ffff);
bmp.draw(_mc);
var copy_mc:MovieClip = _root.createEmptyMovieClip("c_mc", 0);
copy_mc.attachBitmap(bmp, 2);
copy_mc._x = _mc._x;
copy_mc._y = _mc._y;
_mc._visible = false;
var startPointoint = new Point(copy_mc._x, copy_mc._y);
var endPointoint = new Point();
copy_mc.onEnterFrame = function() {
endPoint.x = _xmouse;
endPoint.y = _ymouse;
if (bmp.hitTest(startPoint, 0, endPoint)) {
  trace(endPoint);
}
};
效果
[attach]348382[/attach

附件

未命名-2.fla (48 KB)

2008-7-28 16:42, 下载次数: 109

未命名-2.swf (509 Bytes)

2008-7-28 16:42, 下载次数: 217

TOP

发新话题