码迷,mamicode.com
首页 > 其他好文 > 详细

kinematic与static刚体不会触发任何接触回调

时间:2017-05-10 11:27:24      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:pac   back   UI   image   sts   log   mic   lis   main   

Main.as

package{
    import Box2D.Common.Math.b2Vec2;
    import Box2D.Dynamics.b2Body;
    import Box2D.Dynamics.Contacts.b2Contact;
    import Box2D.Collision.b2Manifold;
    import Box2D.Dynamics.b2ContactImpulse;
    
    public class Main extends BaseMain{
        
        
        public function Main(){
            super(new b2Vec2(0,0));
        }
        
        
        override protected function init():void{
            UIManager.getInstance().init(this);
            
            var boxA:b2Body=createBox(30,30,50,300);
            var circle:b2Body=createCircle(15,50,400);
            var boxB:b2Body=createBox(50,200,700,300);
            boxA.SetUserData({type:"boxA"});
            circle.SetUserData({type:"circle"});
            boxB.SetUserData({type:"boxB"});
            
            boxB.SetType(b2Body.b2_staticBody);
            
            boxA.SetType(b2Body.b2_kinematicBody);
            boxA.SetLinearVelocity(new b2Vec2(10,0));
            boxA.SetPreSolveCallback(preSolve);
            boxA.SetContactBeginCallback(contactBegin);
            boxA.SetContactEndCallback(contactEnd);
            boxA.SetPostSolveCallback(postSolve);
            
            circle.SetType(b2Body.b2_dynamicBody);
            circle.SetLinearVelocity(new b2Vec2(5,0));
            circle.SetPreSolveCallback(preSolve);
            circle.SetContactBeginCallback(contactBegin);
            circle.SetContactEndCallback(contactEnd);
            circle.SetPostSolveCallback(postSolve);
        }
        
        private function contactBegin(contact:b2Contact,other:b2Body):void{
            UIManager.getInstance().print("contactBegin:"+other.GetUserData().type);
        }
        
        private function contactEnd(contact:b2Contact,other:b2Body):void{
            UIManager.getInstance().print("contactEnd:"+other.GetUserData().type);
        }
        
        private function postSolve(contact:b2Contact,impulse:b2ContactImpulse,other:b2Body):void{
            UIManager.getInstance().print("postSolve:"+other.GetUserData().type);
        }
        
        private function preSolve(contact:b2Contact,oldManifold:b2Manifold,other:b2Body):void{
            UIManager.getInstance().print("preSolve:"+other.GetUserData().type);
            
        }
        
        override protected function stepBefore():void{ 
            
        }
        
        
    };
}

示例:

技术分享

源码下载:链接:http://pan.baidu.com/s/1bpL8chh 密码:qui7

kinematic与static刚体不会触发任何接触回调

标签:pac   back   UI   image   sts   log   mic   lis   main   

原文地址:http://www.cnblogs.com/kingBook/p/6834574.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!