Physicsbody doesn't adhere to node's anchor point

前端 未结 7 1228
陌清茗
陌清茗 2020-12-09 15:09

My scene has a bunch of rectangles with physics bodies that are the same size as the rectangle. I like to anchor all of my objects to CGPointZero, however I\'ve noticed when

7条回答
  •  再見小時候
    2020-12-09 15:21

    Swift 4.1

    let centerPoint = CGPoint(x: house1.size.width / 2 - (house1.size.width * house1.anchorPoint.x), y: house1.size.height / 2 - (house1.size.height * house1.anchorPoint.y))

    house1.physicsBody = SKPhysicsBody(rectangleOf: house1.size, center: centerPoint)

提交回复
热议问题