2014-09-23 22 views
-2

是否有人知道如何沿着box2d distancejoint繪製線?AS3如何繪製沿着box2d distancejoint的線

var distanceJointDef:b2DistanceJointDef = new b2DistanceJointDef(); 

請幫助!!!

+0

「def」變量是用於創建關節的定義。您將需要使用創建的關節自行繪製線。通常你可以使用GetAnchor1和GetAnchor2來獲取點。 – iforce2d 2014-09-24 00:48:02

回答

1

我從來沒有使用b2DistanceJoinDef,但glancing at the documentation它看起來像有兩個矢量分你畫之間,就這麼簡單的東西線:

var start:b2Vec2 = distanceJointDef.localAnchor1; 
var end:b2Vec2 = distanceJointDef.localAnchor2; 
var line:b2Vec2 = end.Subtract(start); 

var shape:Shape = new Shape(); 

shape.x = start.x; 
shape.y = start.y; 

shape.graphics.lineStyle(1, 0xFF0000); 
shape.graphics.lineTo(line.x, line.y); 

stage.addChild(shape); 

我想你會擴展將x和y值降至合適的大小(Box2D以米爲單位)。