物理 body 不符合形状?
physics body not inline with shape?
出于某种原因,当我在 skshapenode 周围应用物理 body 时,它会将物理 body 放置在实际形状的左侧和下方,即使物理参数 [=14] =] 来自形状。有谁知道为什么?谢谢。
-(SKShapeNode*) createGround1
{
//create a rectangle
ground1 = [SKShapeNode shapeNodeWithRect:CGRectMake(0, 0, 300, 19)];
ground1.position = CGPointMake(800, 500);
//applies physics to rectangle
ground1.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize: CGSizeMake(ground1.frame.size.width, ground1.frame.size.height)];
ground1.physicsBody.allowsRotation = false;
ground1.physicsBody.dynamic = false;
ground1.physicsBody.restitution = 0.0;
return ground1;
}
出现这种情况是因为定位点不同。您需要像这样为您的物理体定义一个中心点:
ground1.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(ground1.frame.size.width, ground1.frame.size.height) center:CGPointMake(150, 9.5)];
出于某种原因,当我在 skshapenode 周围应用物理 body 时,它会将物理 body 放置在实际形状的左侧和下方,即使物理参数 [=14] =] 来自形状。有谁知道为什么?谢谢。
-(SKShapeNode*) createGround1
{
//create a rectangle
ground1 = [SKShapeNode shapeNodeWithRect:CGRectMake(0, 0, 300, 19)];
ground1.position = CGPointMake(800, 500);
//applies physics to rectangle
ground1.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize: CGSizeMake(ground1.frame.size.width, ground1.frame.size.height)];
ground1.physicsBody.allowsRotation = false;
ground1.physicsBody.dynamic = false;
ground1.physicsBody.restitution = 0.0;
return ground1;
}
出现这种情况是因为定位点不同。您需要像这样为您的物理体定义一个中心点:
ground1.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(ground1.frame.size.width, ground1.frame.size.height) center:CGPointMake(150, 9.5)];