标签:
如果两个刚体使用PreListener忽略了它的碰撞时,如果这时你使用InteractionListener来侦听它们的碰撞还是可以侦听到的:
1 package { 2 import com.bit101.components.TextArea; 3 import nape.callbacks.CbEvent; 4 import nape.callbacks.CbType; 5 import nape.callbacks.InteractionCallback; 6 import nape.callbacks.InteractionListener; 7 import nape.callbacks.InteractionType; 8 import nape.callbacks.PreCallback; 9 import nape.callbacks.PreFlag; 10 import nape.callbacks.PreListener; 11 import nape.phys.Body; 12 /** 13 * ... 14 * @author kingBook 15 * 2015-02-01 21:18 16 */ 17 public class Main extends BaseMain { 18 19 public function Main() { 20 super({gravity:{x:0,y:0}}); 21 22 } 23 24 private var _box:Body; 25 private var _circle:Body; 26 private var _boxCbType:CbType=new CbType(); 27 private var _circleCbType:CbType=new CbType(); 28 private var _textArea:TextArea; 29 override protected function createBodies():void { 30 //矩形刚体 31 _box=createBox(50,50,100,200); 32 _box.cbTypes.add(_boxCbType); 33 _box.space=_space; 34 35 //圆形刚体 36 _circle=createCircle(30,250,200); 37 _circle.cbTypes.add(_circleCbType); 38 _circle.space=_space; 39 40 _space.listeners.add(new PreListener(InteractionType.COLLISION,_boxCbType,_circleCbType,ignoreHandler)); 41 _space.listeners.add(new InteractionListener(CbEvent.BEGIN,InteractionType.COLLISION,_boxCbType,_circleCbType,onHitBegin)); 42 43 //文本域 44 _textArea=new TextArea(this,5,5); 45 } 46 47 private function ignoreHandler(cb:PreCallback):PreFlag{ 48 return PreFlag.IGNORE; 49 } 50 51 private function onHitBegin(cb:InteractionCallback):void{ 52 _textArea.text += "hit\n" 53 } 54 55 } 56 57 }
拖动矩形刚体与圆形刚体相碰依然可以看到输出: hit
源码下载:http://yunpan.cn/cKBwzyNkfJN7P 访问密码 5883
使用PreListener与InteractionListener的一个小发现
标签:
原文地址:http://www.cnblogs.com/kingBook/p/4266103.html