[英]b2Body questions
I have 2 questions with b2Body: 我对b2Body有2个问题:
Thanks! 谢谢!
A b2BodyDef
is used to define information about a body as a whole, such as position and rotation. b2BodyDef
用于定义有关整体物体的信息,例如位置和旋转。 Compared to the other information you require for a b2Body
, such as friction and resititution , that is defined on a per fixture basis using b2Fixtures
. 与
b2Body
所需的其他信息相比,例如摩擦和复位 ,这些信息是使用b2Fixtures
在每个夹具的基础上b2Fixtures
。 The b2Body
is an amalgamation of a body definition and at least one fixture. b2Body
是身体定义和至少一个固定装置的合并。
With regard to creating the body from a predefined rect, I'd advise using setAsBox:
assuming you are using a b2PolygonShape
. 关于从预定义矩形创建主体,我建议使用
setAsBox:
假设您正在使用b2PolygonShape
。
The way I usually accomplish the joining of the two is to create a class called BodyNode
which has ivars of a b2Body
and a CCSprite
. 我通常将两者结合
BodyNode
的方式是创建一个名为BodyNode
的类,该类具有b2Body
和CCSprite
。 Assign either the BodyNode
, ie self
or the sprite as the userData
and update them as follows: 将
BodyNode
(即self
或sprite)分配为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.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.