当我将physicsBody设置为带有完整圆圈的图像时,它可以正常工作! 喜欢:
sprite.physicsBody = [SKPhysicsBody bodyWithTexture:sprite.texture size:sprite.size];
但如果我有点像这样的图像,如何设置physicsBody:
http://www.i2symbol.com/images/symbols/geometry/dotted_circle_u25CC_icon_256x256.png
答案 0 :(得分:0)
这会给你你想要的东西。只需要添加图形。您可能还想将它们添加到父级精灵中。复制并粘贴它以检查它,然后根据您的需要调整它。希望它有所帮助:)
let centerPoint = CGPoint(x: self.size.width/2, y: self.size.height/2)
for i in 1...8 {
let circleSection = SKSpriteNode(color: SKColor.redColor(), size: CGSize(width: 30, height: 10))
circleSection.physicsBody = SKPhysicsBody(rectangleOfSize: circleSection.size)
let angle = CGFloat(M_PI_4) * CGFloat(i)
let distFromCtr = CGFloat(100)
var angleToPt = CGPoint(
x: cos(angle) * distFromCtr,
y: sin(angle) * distFromCtr
)
angleToPt.x += centerPoint.x
angleToPt.y += centerPoint.y
circleSection.position = angleToPt
circleSection.zRotation = angle + CGFloat(M_PI_2)
self.addChild(circleSection)
}