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{
	
	}
    

}
原文地址:https://www.cnblogs.com/kingBook/p/13038314.html