碰撞迅速的SKPhysicsbody错误

时间:2016-03-11 11:06:30

标签: xcode swift skphysicsbody

我必须遵循为我的敌人制作自定义physicsBody的代码。 请参阅以下代码:

let offsetX = CGFloat(Enemy.frame.size.width * Enemy.anchorPoint.x)
let offsetY = CGFloat(Enemy.frame.size.height * Enemy.anchorPoint.y)

let path = CGPathCreateMutable()

CGPathMoveToPoint(path, nil, 25 - offsetX, 73 - offsetY)
CGPathAddLineToPoint(path, nil, 32 - offsetX, 72 - offsetY)
CGPathAddLineToPoint(path, nil, 45 - offsetX, 66 - offsetY)
CGPathAddLineToPoint(path, nil, 47 - offsetX, 63 - offsetY)
CGPathAddLineToPoint(path, nil, 43 - offsetX, 11 - offsetY)
CGPathAddLineToPoint(path, nil, 25 - offsetX, 2 - offsetY)
CGPathAddLineToPoint(path, nil, 11 - offsetX, 15 - offsetY)
CGPathAddLineToPoint(path, nil, 5 - offsetX, 29 - offsetY)
CGPathAddLineToPoint(path, nil, 5 - offsetX, 30 - offsetY)
CGPathAddLineToPoint(path, nil, 3 - offsetX, 44 - offsetY)
CGPathAddLineToPoint(path, nil, 3 - offsetX, 51 - offsetY)
CGPathAddLineToPoint(path, nil, 7 - offsetX, 65 - offsetY)
CGPathAddLineToPoint(path, nil, 9 - offsetX, 67 - offsetY)
CGPathAddLineToPoint(path, nil, 15 - offsetX, 70 - offsetY)

CGPathCloseSubpath(path)

Enemy.physicsBody = SKPhysicsBody(polygonFromPath: path)

当我运行此代码时,physicsBody的大小只是我图片的一半。并位于图片的左下角。我该如何解决?

1 个答案:

答案 0 :(得分:0)

我认为如果你将所有的值乘以它应该有效! 看下一行代码:

CGPathAddLineToPoint(path, nil, 11*2 - offsetX, 15*2 - offsetY)