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

}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章