CCPhysicsBodyTypeStatic无法正常工作

时间:2014-07-15 12:28:26

标签: cocos2d-iphone physics-engine

我不使用花栗鼠,但只使用PhysicsEngine,cocos 2d v3。

_physicsNode = [CCPhysicsNode node];
_physicsNode.collisionDelegate = self;
_physicsNode.gravity=ccp(0,-165);
_physicsNode.debugDraw = TRUE;
[self addChild:_physicsNode];

CCNode *handAttachPoint=[CCNode node];
handAttachPoint.physicsBody.type=CCPhysicsBodyTypeStatic;
handAttachPoint.position=ccp(self.contentSize.width/8,self.contentSize.height/2);
handAttachPoint.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius:1.0 andCenter:handAttachPoint.anchorPointInPoints];
//handAttachPoint.physicsBody.collisionMask=@[];
[_physicsNode addChild:handAttachPoint];

我希望节点 handAttachPoint 在窗口中是静态的,但它仍在下降.. :(

任何帮助表示赞赏!!

1 个答案:

答案 0 :(得分:1)

你的订单错了:

handAttachPoint.physicsBody.type = CCPhysicsBodyTypeStatic;

...

handAttachPoint.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius:1.0
                               andCenter:handAttachPoint.anchorPointInPoints];

在第一行物理系统尚未分配,属性为零。分配静态不会在那里做任何事情,它会被忽略。您必须在>初始化和分配物理主体后执行此分配