gpt4 book ai didi

swift - 如何围绕 Sprite 节点分配 SKPhysicsBody,使其完美环绕对象框架

转载 作者:搜寻专家 更新时间:2023-11-01 06:04:51 25 4
gpt4 key购买 nike

我正在尝试制作一个勾勒出 Sprite 节点的物理体,例如:而不是使用 SKPhysicsBody(circleOfSize...) 并只是获取圆形或使用 SKPhysicsBody(RectangleOfSize...) 但我认为有一个“AlphaMask”或类似的东西,如果我的 Sprite 节点是杯子的形状或“V”形状,允许物体进入开放顶部并被卡在“V”内?提前致谢:)

enter image description here enter image description here

所以第一张图片是我在尝试矩形图片时不断得到的,第二张图片是我需要的类型!

最佳答案

我认为最好的解决方案可能是建立一条路径,然后:

SKPhysicsBody.init(edgeLoopFrom: path!)

这是官方源文件:

/**
Creates an edge loop from a path. A loop is automatically created by joining the last point to the first. The path must have no self intersection. Edges have no volume and are intended to be used to create static environments. Edges can collide with body's of volume, but not with each other.
@param path the path to use
*/
public /*not inherited*/ init(edgeLoopFrom path: CGPath)

使用此解决方案,您将能够根据 CGPath 构造(“V”形)精确定义形状。

关于swift - 如何围绕 Sprite 节点分配 SKPhysicsBody,使其完美环绕对象框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40269076/

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