zoukankan      html  css  js  c++  java
  • as3 判断鼠标在非透明区域点击图片

    1. /** 
    2.                  *鼠标事件  
    3.                  * @param evt 
    4.                  *  
    5.                  */                  
    6.                   
    7.                 private function mouseDownHandler(evt:MouseEvent):void  
    8.                 {  
    9.                          if(evt.currentTarget is SceneObject)  
    10.                         {                  
    11.                                 //判断当前点击区是否在最小图形范围内  
    12.                                   
    13.                                 var bmd:BitmapData = new BitmapData(evt.currentTarget.width,evt.currentTarget.height,true0x00000000);  
    14.                                 bmd.draw(evt.currentTarget as SceneObject);  
    15.                                                                    
    16.                                                                 //第一种方法:找到对象的非空白区域,判断鼠标点击点是否在该区域内  
    17.   
    18.                                 ///看帮助 若要确定图像周围的空白区域,请传递 {mask: 0xFFFFFFFF, color: 0xFFFFFFFF} 以查找非空白像素的范围。如果new BitmapData时填充了 0x00000000则传递{mask: 0xFFFFFFFF, color: 0x00000000}  
    19.                                 /*var rect:Rectangle = bmd.getColorBoundsRect(0xffffffff,0x00000000,false);         
    20.                                 trace(rect); 
    21.                                 var minx:Number =  rect.x; 
    22.                                 var miny:Number =  rect.y; 
    23.                                 var maxx:Number = minx + rect.width; 
    24.                                 var maxy:Number = miny + rect.height; 
    25.                                 */  
    26.   
    27.                                                                 //第二种方法 取当前点击点的颜色值 与0x0000000进行判断如果相等则非空白 ,  
    28.                                 /*var color:uint = bmd.getPixel32(evt.localX,evt.localY); 
    29.                                 trace(color.toString(16),0x00000000); //此处 的color值在点击透明区域输出0xffffffff 
    30.                                 */  
    31.   
    32.                                                                  //第三种方法 利用像素碰撞函数hitTest一步解决 0x00000001 为取比0x00000000都大的区域都为非透明像素  
    33.                                 var ptoint = new Point(evt.localX,evt.localY);   
    34.                                 if(bmd.hitTest(new Point(0,0),0x00000001,pt))  
    35.                                 //if(evt.localX>= minx  && evt.localX <= maxx && evt.localY  >= miny  && evt.localY <= maxy)  
    36.                                 //if(color != 0x00000000)  
    37.                                 {  
    38.                                         trace("按下,在内部");  
    39.                                                                                 bmd.dispose();  
    40.                                 }  
    41.                                 else  
    42.                                 {  
    43.                                         trace("按下,不在内部");  
    44.                                         bmd.dispose();  
    45.                                         return;//返回不停止事件流,让鼠标托动背景   
    46.                                 }                        }  
    47.                         evt.stopPropagation();  
    48.                 }  
  • 相关阅读:
    rosservice call ERROR:Unable to load type ... Have you typed 'make'
    查看ubuntu版本号
    VirtualBox虚拟机 host/guest 拷贝粘贴,共享剪贴板,安装guest additions
    traffic_light_bag_file 数据集 下载链接
    ubuntu linux double tab
    ubuntu linux查看cpu信息
    ubuntu linux查看硬盘使用量
    ubuntu查看nvidia显卡状态
    ibus
    windows7 屏幕亮图胡乱变化
  • 原文地址:https://www.cnblogs.com/lingLuoChengMi/p/9264480.html
Copyright © 2011-2022 走看看