AS3透明碰撞 自动判别图片透明区域碰撞
2011-10-14 12:45
375 查看
package helper { import com.pblabs.engine.PBE; import flash.display.BitmapData; import flash.display.MovieClip; import flash.geom.ColorTransform; import flash.geom.Matrix; import flash.geom.Rectangle; /** * 矩形碰撞检测 * */ public class HH_CollisionDetection { public function HH_CollisionDetection() { } /** * param p_clip1 元件1 * param p_clip2 元件2 * param p_alphaTolerance * return * */ public static function checkForCollision(p_clip1:*, p_clip2:*, p_alphaTolerance:Number=250):Rectangle { // 获取对象坐标区域 var bounds1:Object=p_clip1.getBounds(PBE.mainStage); var bounds2:Object=p_clip2.getBounds(PBE.mainStage); // 检测两矩形是否碰撞 if (((bounds1.right < bounds2.x) || (bounds2.right < bounds1.x)) || ((bounds1.bottom < bounds2.y) || (bounds2.bottom < bounds1.y))) { return null; } // 区域测试: var bounds:Object={}; bounds.x=Math.max(bounds1.x, bounds2.x); bounds.right=Math.min(bounds1.right, bounds2.right); bounds.y=Math.max(bounds1.y, bounds2.y); bounds.bottom=Math.min(bounds1.bottom, bounds2.bottom); var img:BitmapData=new BitmapData(bounds.right - bounds.x, bounds.bottom - bounds.y, false); var mat:Matrix=p_clip1.transform.concatenatedMatrix; mat.tx-=bounds.x; mat.ty-=bounds.y; img.draw(p_clip1, mat, new ColorTransform(1, 1, 1, 1, 255, -255, -255, p_alphaTolerance)); mat=p_clip2.transform.concatenatedMatrix; mat.tx-=bounds.x; mat.ty-=bounds.y; img.draw(p_clip2, mat, new ColorTransform(1, 1, 1, 1, 255, 255, 255, p_alphaTolerance), "difference"); var intersection:Rectangle=img.getColorBoundsRect(0xFFFFFFFF, 0xFF00FFFF); if (intersection.width == 0) { return null; } intersection.x+=bounds.x; intersection.y+=bounds.y; return intersection; } } }
相关文章推荐
- as3 操作图片,获取,设置实际像素,扣除透明区域
- 如何拉伸有透明区域的png图片来做UIButton的背景图片
- Android ImageView包含透明区域的图片点击事件处理
- Android中不规则图片按钮透明区域的点击效果
- 取得图片的透明区域
- 如何在asp.net中用C#自动生成透明的GIF图片
- js实现固定显示区域内自动缩放图片的方法
- as3动态加载多张图片,自动缩放并加鼠标边框![新手]
- png图片 透明区域如何 让其不响应鼠标事件?
- [html] <a> and <input> can not click in IE6 when use png fixed -- IE6下png图片和png背景透明导致该区域的链接和按钮无效
- 图片在固定区域内自动伸缩(自适应)
- AS3 如何让鼠标不响应透明区域
- cocos2d中对CCMenu 实现扩展使触摸正常图片的透明区域不触发事件
- 子图的分割,子图依据图片中的透明区域自行分割
- Word2003入门动画教程70:在图片中添加透明区域
- as3 抠图、选取透明区域
- Android ImageView图片透明区域不响应点击事件,不规则图片透明区域响应点击事件
- 指定区域的图片自动按比例缩小的js代码(防止页面被图片撑破)
- IOS 多个ImageView图片层叠透明区域点击事件穿透
- 把android 中图片局部区域改为透明