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

标签 swift sprite-kit

我正在尝试制作一个勾勒出 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/

相关文章:

java - 如何为 Swift 语言创建 Java ANTLR 解析器?

ios - Swift 4.2 - 类型 '(____) -> () -> (____)' 的值没有成员 'childNode'

swift - 如何正确连接GameScene.swift和GameScene.sks?

ios - SpriteKit - 动画 SKShapeNode 形状路径

ios - 来自拍摄的真实物体的 360 度可旋转物体

swift - 如何防止CALayer绘制背景色?

ios - UIPickerView 将数据传递给容器 View

swift - 展开 swift 可选类型时,性能会受到什么影响(如果有的话)?

ios - 将 GameViewController.swift 链接到 GameScene.swift

ios - Kinvey Swift 3 KCSCus​​tomEndpoints