kingBook

导航

CocosCreator 手动设置刚体接触回调函数

const {ccclass,property}=cc._decorator;

@ccclass
export default class Test extends cc.Component{
	
	@property({type:cc.RigidBody,visible:true})
	private _rigidBody:cc.RigidBody=null;
	
	onLoad(){
		this._rigidBody.enabledContactListener=true;
		//手动添加onPreSolve回调,使用bind方法绑定this或Lambed表达式,否则this会丢失
		this._rigidBody.onPreSolve=this.onBodyPreSolve.bind(this);
		
		/*this._rigidBody.onPreSolve=(contact:cc.PhysicsContact,selfCollider:cc.PhysicsCollider,otherCollider:cc.PhysicsCollider)=>{
			this.onBodyPreSolve(contact,selfCollider,otherCollider);
		};*/
	}
	
	private onBodyPreSolve(contact:cc.PhysicsContact,selfCollider:cc.PhysicsCollider,otherCollider:cc.PhysicsCollider):void{
	
	}
    

}

posted on 2020-06-03 16:24  kingBook  阅读(488)  评论(0编辑  收藏  举报