Nape "不动"刚体的碰撞交互
"不动"刚体,这里指的是以下两类刚体:
1.刚体的allowMovement和allowRotation都设false的刚体
2.KINEMATIC类型的刚体
如下代码,测试发现输出面板没有内容输出,侦听不到两者的碰撞。
1 package { 2 import nape.callbacks.CbEvent; 3 import nape.callbacks.CbType; 4 import nape.callbacks.InteractionCallback; 5 import nape.callbacks.InteractionListener; 6 import nape.callbacks.InteractionType; 7 import nape.phys.Body; 8 import nape.phys.BodyType; 9 import com.bit101.components.TextArea; 10 11 public class Main extends BaseMain { 12 13 public function Main() { 14 super({gravity:{x:0,y:0}}); 15 } 16 private var _textArea:TextArea; 17 private const C_A:CbType = new CbType(); 18 private const C_B:CbType = new CbType(); 19 override protected function createBodies():void { 20 var body1:Body=createBox(30,30,80,200); 21 body1.cbTypes.add(C_A); 22 body1.allowMovement = body1.allowRotation=false;//不允许移动、旋转 23 body1.velocity.x=300; 24 body1.space = _space; 25 26 var body11:Body=createBox(30,30,50,300); 27 body11.cbTypes.add(C_A); 28 body11.type = BodyType.KINEMATIC;//设为KINEMATIC刚体类型 29 body11.velocity.x=300; 30 body11.space = _space; 31 32 var body2:Body = createBox(30,300,400,200); 33 body2.cbTypes.add(C_B); 34 body2.type = BodyType.STATIC; 35 body2.space = _space; 36 37 _space.listeners.add(new InteractionListener(CbEvent.BEGIN,InteractionType.COLLISION,C_A,C_B,a_bHandler)); 38 39 _textArea = new TextArea(this); 40 print("check begin....."); 41 } 42 43 private function print(text:String):void{ 44 _textArea.text+=text+"\n" 45 } 46 47 private function a_bHandler(cb:InteractionCallback):void{ 48 print("hit"); 49 } 50 51 } 52 53 }
源码下载:http://yunpan.cn/cmXEYfHw7DbJF 访问密码 b60d