2011-10-17 18 views
0

我有2個問題與b2Body:b2Body問題

  1. 是什麼b2Body和b2BodyDef之間的區別?
  2. 我該如何添加一個b2Body到一個CCScene中,並且我已經編寫了一個CGRect的座標?另外我怎麼會添加userData到它,所以我可以保持對此的參考?

謝謝!

回答

1

A b2BodyDef用於定義關於身體作爲一個整體的信息,如位置和旋轉。與b2Body所需的其他信息相比,如摩擦resshitution,這是使用b2Fixtures以固定爲基礎定義的。 b2Body是一個身體定義和至少一個燈具的融合。

關於從預定義矩形創建身體,我建議使用setAsBox:假設您使用的是b2PolygonShape

我通常完成兩者加入的方式是創建一個名爲BodyNode的類,它的ivars爲b2BodyCCSprite。無論是分配的BodyNode,即self或遊動爲userData和更新它們如下:

-(void) onEnter 
{ 
    [self scheduleUpdate]; 
    [super onEnter]; 
} 

-(void) update:(ccTime) dt 
{ 
    //Update the position of the sprite to the position of the body 
    //Update the rotation of the body to the rotation of the sprite. Take care to note that the rotation of the sprite is in degrees whereas the rotation of the body is in radians. 
} 
+0

感謝您的信息! –