问题
for some reason when i apply a physics body around the skshapenode it places the physics body more to the left and downwards of the actual shape even though the parameters of the physics body comes from the shape. does anyone know why? thanks.
-(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;
}
回答1:
This happens because the anchor points are different. You need to define a center point for your physics body like this:
ground1.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(ground1.frame.size.width, ground1.frame.size.height) center:CGPointMake(150, 9.5)];
来源:https://stackoverflow.com/questions/29869574/physics-body-not-inline-with-shape