I have 2 questions with b2Body:
- What is the difference between b2Body and b2BodyDef?
- How would I add a b2Body to a CCScene with coordinates from a CGRect which I already have coded? Also how would I add userData to it so I can keep a reference to this?
Thanks!
A
b2BodyDefis used to define information about a body as a whole, such as position and rotation. Compared to the other information you require for ab2Body, such as friction and resititution, that is defined on a per fixture basis usingb2Fixtures. Theb2Bodyis an amalgamation of a body definition and at least one fixture.With regard to creating the body from a predefined rect, I’d advise using
setAsBox:assuming you are using ab2PolygonShape.The way I usually accomplish the joining of the two is to create a class called
BodyNodewhich has ivars of ab2Bodyand aCCSprite. Assign either theBodyNode, i.e.selfor the sprite as theuserDataand update them as follows: