xcode - SKPhysicsbody 碰撞快速错误

标签 xcode swift skphysicsbody

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

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)

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

最佳答案

我发现如果你将所有的值相乘,它应该有效! 请参阅下一行代码:

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

关于xcode - SKPhysicsbody 碰撞快速错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35938626/

相关文章:

ios - 用于嵌入式框架的 swift 中 Venmo iOS SDK 的导入语句

ios - 点击时切换 UICollectionView Cell 的选择/取消选择状态 - Swift

ios - 需要在 UICollectionView 中显示视频和图片

swift - 导航按钮需要从最后一个 View 转到第一个 View

swift - 如何删除一些被 Xcode 复制的 Swift 库?

swift - 以编程方式连接到 VPN 不断要求提供系统钥匙串(keychain)凭据

Swift-通过角度设置物理体速度

ios - 带有categoryBitMask的Sprite仍然返回 'nil'

ios - SKPhysicsContactDelegate 协议(protocol)方法未被调用

ios - 自定义类不显示在属性检查器中