physics body not inline with shape?

a 夏天 提交于 2019-12-13 03:37:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!