Change a SKPhysicsBody's body shape

為{幸葍}努か 提交于 2020-01-03 21:08:45

问题


I don't want to change ANYTHING other than the body that defines the shape of a SKPhysicsBody. How do I do this?

I can't seem to find where I can change this.

Or even commentary on how to change it.

Yes, I know this has to be done carefully, so that it avoids all possible new collisions, overlaps, etc. But putting that aside, how do I change the body of an SKPhysicsBody?


回答1:


You can manually create a custom shape for a physics body using CGMutablePath, then pass it into the SKPhysicsBody constructor.

For example:

let path = CGMutablePath()
path.move(to: CGPoint(.....))
path.addLine(to: CGPoint(.....))

let customPhysicsBody = SKPhysicsBody(edgeChainFrom: path)


来源:https://stackoverflow.com/questions/41532393/change-a-skphysicsbodys-body-shape

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!