gpt4 book ai didi

xcode - SKPhysicsbody 碰撞快速错误

转载 作者:行者123 更新时间:2023-11-30 13:37:17 26 4
gpt4 key购买 nike

我必须遵循为我的敌人制作自定义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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com