·您当前的位置:首页 > 技术教程 > AS2与AS3技术 >

[AS3]as3精确到点的碰撞测试源代码示例

时间:2013-03-01 10:59cnblogs.com
[AS3]as3精确到点的碰撞测试源代码示例,as3碰撞,as3精确碰撞,碰撞

[AS3]as3精确到点的碰撞测试源代码示例

  1. package 
  2.     import com.ui.Star; 
  3.      
  4.     import flash.display.Bitmap; 
  5.     import flash.display.BitmapData; 
  6.     import flash.display.Sprite; 
  7.     import flash.display.StageAlign; 
  8.     import flash.display.StageScaleMode; 
  9.     import flash.events.MouseEvent; 
  10.     import flash.filters.GlowFilter; 
  11.     import flash.geom.Matrix; 
  12.     import flash.geom.Point; 
  13.      
  14.     public class Main extends Sprite 
  15.     { 
  16.         private var bmpd1:BitmapData; 
  17.         private var bmp1:Bitmap; 
  18.         private var bmpd2:BitmapData; 
  19.         private var bmp2:Bitmap; 
  20.          
  21.         public function Main():void 
  22.         {        
  23.            //cuplayer.com提示:初始化代码      
  24.             init(); 
  25.         } 
  26.         private function init():void 
  27.         { 
  28.             stage.align = StageAlign.TOP_LEFT; 
  29.             stage.scaleMode = StageScaleMode.NO_SCALE; 
  30.              
  31.             var star:Star = new Star(50); 
  32.              
  33.             bmpd1 = new BitmapData(100,100,true,0); 
  34.             bmpd1.draw(star, new Matrix(1,0,0,1,50,50)); 
  35.             bmp1 = new Bitmap(bmpd1); 
  36.             bmp1.x = 200
  37.             bmp1.y = 200
  38.             this.addChild(bmp1); 
  39.              
  40.             bmpd2 = new BitmapData(100,100,true,0); 
  41.             bmpd2.draw(star, new Matrix(1,0,0,1,50,50)); 
  42.             bmp2 = new Bitmap(bmpd2); 
  43.             this.addChild(bmp2); 
  44.              
  45.             stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMoving); 
  46.         } 
  47.         private function onMouseMoving(event:MouseEvent):void 
  48.         { 
  49.             bmp2.x = mouseX - 50; 
  50.             bmp2.y = mouseY - 50; 
  51.              
  52.             if(bmpd1.hitTest(new Point(bmp1.x, bmp1.y), 255, bmpd2, new Point(bmp2.x, bmp2.y), 255)) 
  53.             { 
  54.                 bmp1.filters = [new GlowFilter()]; 
  55.                 bmp2.filters = [new GlowFilter()]; 
  56.             } 
  57.             else 
  58.             { 
  59.                 bmp1.filters = []; 
  60.                 bmp2.filters = []; 
  61.             } 
  62.         } 
  63.     } 

 

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器