[LayaAir 2.0][LayaAir 2.0] 如何用代码为Spirte添加2d物理特性
								官方的2d物理引擎文档都是IDE篇的。
 
我试着用代码实现物理效果
产生的效果是boll1会自由落体,但不会与挡板发生物理碰撞而是直接穿过挡板(如图1),请问要如何修改代码。
图1
 
																
																																
															
														我试着用代码实现物理效果
class CollisionBoll extends Laya.Sprite {
    
    private _boll1:Laya.Sprite;
    constructor() { 
        super(); 
        //物理模块
        this._boll1 = new Laya.Sprite();
        this.addChild(this._boll1);
        this._boll1.x = 20;
        this._boll1.loadImage('comp/btn_close.png');
        let box:laya.physics.BoxCollider = this._boll1.addComponent(laya.physics.BoxCollider);
        box.height = 60;
        box.width = 28;
        //添加刚体
        this._boll1.addComponent(Laya.RigidBody);
        //创建挡板
        this.createPanel();
    }
    private createPanel():void {
        let panel:Laya.Sprite = new Laya.Sprite();
        panel.graphics.drawRect(0,100,100,20,0xffffff);
        this.addChild(panel);
        let box:laya.physics.BoxCollider = panel.addComponent(laya.physics.BoxCollider);
        box.height = 20;
        box.width = 100;
        let rigid:Laya.RigidBody = panel.addComponent(Laya.RigidBody);
        rigid.type = 'static';
    }产生的效果是boll1会自由落体,但不会与挡板发生物理碰撞而是直接穿过挡板(如图1),请问要如何修改代码。
图1
没有找到相关结果
									已邀请:
																	
							

 
1 个回复
bpmf_d
赞同来自: