as3碰撞检测(两图重叠区)(例子)
来源:互联网 发布:淘宝贷款逾期四个月了 编辑:程序博客网 时间:2024/04/29 21:33
1 package
2 {
3
4 import flash.display.Sprite;
5 import flash.events.MouseEvent;
6 import ws.tink.display.HitTest;
7 import flash.geom.Rectangle;
8
9 public class ComplexIntersectionRectangle extends Sprite
10 {
11
12 private var _circle0 : Sprite;
13 private var _circle1 : Sprite;
14 private var _hit : Boolean;
15 private var _intersection : Sprite;
16
17 public function ComplexIntersectionRectangle()
18 {
19 super();
20
21 initialize();
22 }
23
24 private function initialize():void
25 {
26
27 _circle0 = new Sprite();
28 _circle0.x = 50;
29 _circle0.y = 100;
30 _circle0.addEventListener( MouseEvent.MOUSE_DOWN, onCircleMouseDown );
31 draw( _circle0, 0xFFFFFF );
32 addChild( _circle0 );
33
34 _circle1 = new Sprite();
35 _circle1.x = 250;
36 _circle1.y = 100;
37 _circle1.addEventListener( MouseEvent.MOUSE_DOWN, onCircleMouseDown );
38 draw( _circle1, 0xFFFFFF );
39 addChild( _circle1 );
40
41 _intersection = new Sprite();
42 addChild( _intersection );
43
44 _hit = false;
45
46 stage.addEventListener( MouseEvent.MOUSE_MOVE, onStageMouseMove );
47 stage.addEventListener( MouseEvent.MOUSE_UP, onStageMouseUp );
48 }
49
50 private function onCircleMouseDown( event:MouseEvent ):void
51 {
52 var circle:Sprite = Sprite( event.target );
53 circle.startDrag( false );
54 }
55
56 private function onStageMouseMove( event:MouseEvent ):void
57 {
58 var intersection:Rectangle = HitTest.complexIntersectionRectangle( _circle0, _circle1, 5 );
59 var hit:Boolean = ( intersection.width > 0 && intersection.height > 0 );
60
61 _intersection.graphics.clear();
62 if( hit )
63 {
64 _intersection.graphics.beginFill( 0xFF0000, 0.5 );
65 _intersection.graphics.drawRect( intersection.x, intersection.y, intersection.width, intersection.height );
66 _intersection.graphics.endFill();
67 }
68
69 if( hit != _hit )
70 {
71 _hit = hit;
72 var color:Number = ( _hit ) ? 0x00FF00 : 0xFFFFFF;
73 draw( _circle0, color );
74 draw( _circle1, color );
75 }
76 }
77
78 private function onStageMouseUp( event:MouseEvent ):void
79 {
80 _circle0.stopDrag();
81 _circle1.stopDrag();
82 }
83
84 private function draw( circle:Sprite, color:Number ):void
85 {
86 circle.graphics.clear();
87 circle.graphics.beginFill( color, 1 )
88 circle.graphics.drawCircle( 0, 0, 25 );
89 circle.graphics.endFill();
90 }
91 }
92 }
- as3碰撞检测(两图重叠区)(例子)
- AS3 碰撞检测
- 转 第九章 碰撞检测(as3.0)
- as3中碰撞检测的注意
- as3.0像素级碰撞检测
- AS3.0碰撞检测 hitTestObject 与 hitTestPoint
- AS3.0碰撞检测 hitTestObject 与 hitTestPoint
- AS3自带的三种碰撞检测方式
- 超级玛丽碰撞检测(跑酷碰撞检测)
- Unity3D检测(碰撞、射线)
- Unity3D检测(碰撞、射线)
- 高级碰撞检测(一)
- Ogre1.8.1射线实现碰撞检测例子源代码
- Unreal Engine 4 物理模拟之物理碰撞、重叠与射线检测
- 数学建模-两球的高级碰撞检测
- 碰撞检测
- 碰撞检测
- 碰撞检测
- sws_getContext用法实例
- Jquery Ajax for ASP.NET
- linux定时任务的设置
- ffmpeg中sws_scale()用法实例
- 定义typedef struct 重定义错误解决办法
- as3碰撞检测(两图重叠区)(例子)
- core文件生成时代进程号
- SequenceFile 解决hadoop小文件问题
- opencv学习
- opencv学习
- opencv学习
- OSS中心服务器集群方案
- 基于SOAP协议的WEB服务研究
- 【数据库】导致“mysql has gone away”的两种情况