本帖最后由 ywx620 于 2017-11-30 10:52 编辑
之前想用大神拉登6666的p2DebugDraw类来写点测试用例
结果发现用不了,最后测试跟踪进去发现我在外面画一个100*100像素的小方块。
可是在p2DebugDraw里面放大了好多倍,方块大小变成好几千像素。然后就没有深究进去了。
于是自己写了个P2World类,在里面创建刚体和皮肤都集成在一个类里面。Main主类只是用来点击加载刚体用。
另外有哪个朋友有深入研究过拉登6666的p2DebugDraw,也请帮忙分析一下哈
来看一下效果图
演示地址
http://ywx620.com/egret/P2Demo/
手机可扫码演示
在Main类中初始化P2Demo
var p2World=new P2World();
p2World.createBg(0X00FFFF,this.stage);//创建背景
//创建左下向平面用来阻止刚体跑出屏幕
p2World.createPlane(Math.PI,0,this.stage.stageHeight);
p2World.createPlane(-Math.PI/2,0,0);
p2World.createPlane(Math.PI/2,this.stage.stageWidth,0);
单击后创建刚体
[mw_shl_code=applescript,true]private onClick(e:egret.TouchEvent):void
{
this.p2World.index++;
var index=this.p2World.index;
var random:number=Math.random();
var radius:number=30+20*random;
var body:p2.Body;
var skin:egret.Sprite;
if(random<0.3){//圆形
body=this.p2World.createCircleBodyShape(radius,index);
skin=this.p2World.drawCircle(radius,body);
}else if(random<0.6){//正方形
body=this.p2World.createBoxBodyShape(radius,radius,index);
skin=this.p2World.drawBox(radius,radius,body);
}else {//长方形
var height:number=radius*2;
body=this.p2World.createBoxBodyShape(radius,height,index);
skin=this.p2World.drawBox(radius,height,body);
}
body.position=[e.stageX,e.stageY];
skin.x=e.stageX;
skin.y=e.stageY;
}[/mw_shl_code]
源码下载地址
|
|