0
我使用starling + as3在我的移動應用程序中創建舞臺牆壁和一個盒子。Starling + Box2d - 碰撞不精確
好了,現在當我測試應用程序的盒子下降,但它不匹配牆壁,彷彿有 是一個偏移:
https://www.dropbox.com/s/hd4ehnfthh0ucfm/box.png
這裏是我創建的盒(牆壁和盒子)。
看起來好像有一個隱藏的偏移量,你怎麼看?
public function createBox(x:Number, y:Number, width:Number, height:Number, rotation:Number = 0, bodyType:uint = 0):void {
/// Vars used to create bodies
var body:b2Body;
var boxShape:b2PolygonShape;
var circleShape:b2CircleShape;
var fixtureDef:b2FixtureDef = new b2FixtureDef();
fixtureDef.shape = boxShape;
fixtureDef.friction = 0.3;
// static bodies require zero density
fixtureDef.density = 0;
var quad:Quad;
bodyDef = new b2BodyDef();
bodyDef.type = bodyType;
bodyDef.position.x = x/WORLD_SCALE;
bodyDef.position.y = y/WORLD_SCALE;
// Box
boxShape = new b2PolygonShape();
boxShape.SetAsBox(width/WORLD_SCALE, height/WORLD_SCALE);
fixtureDef.shape = boxShape;
fixtureDef.density = 0;
fixtureDef.friction = 0.5;
fixtureDef.restitution = 0.2;
// create the quads
quad = new Quad(width, height, Math.random() * 0xFFFFFF);
quad.pivotX = 0;
quad.pivotY = 0;
// this is the key line, we pass as a userData the starling.display.Quad
bodyDef.userData = quad;
//
body = m_world.CreateBody(bodyDef);
body.CreateFixture(fixtureDef);
body.SetAngle(rotation * (Math.PI/180));
_clipPhysique.addChild(bodyDef.userData);
}
是的我也注意到了,setasbox是照顧 – mirzahat