ios - SpriteKit : How to make physics body of a sprite to copy an actual image?

标签 ios swift sprite-kit

我知道如何在 gamescene.sks 中做到这一点——你只需要选择一个 Sprite 并选中 body 类型形式的“alpha mask”。 但是如何以编程方式进行呢?我担心我对 .sks 的操作会以失败告终。所以我想通过快速代码来完成。我查看了物理体相关的方法和属性,但没有发现任何接近“alpha mask”的东西

最佳答案

您没有找到任何与 alpha 相关的内容?可能想仔细看看... bodyWithTexture:size: 的文档说(强调):

Use this method when your sprite has a shape that you want replicated in its physics body... A new physics body is created that includes all of the texels in the texture that have a nonzero alpha value.

另见 bodyWithTexture:alphaThreshold:size:如果您想更改 alpha 阈值。

关于ios - SpriteKit : How to make physics body of a sprite to copy an actual image?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28840907/

相关文章:

android - 如何在离线平板电脑应用程序中显示图像

ios - 如何设置可以在 swift 5 中实例化后推送的初始 viewController

ios - 为什么 iOS Swift 无法更改 UITabBar 角标(Badge)字体?

ios - 使用可变变量重复 for 循环的一次迭代

ios - 找到弹跳 SKSpriteNode 将采用的路径

ios - 如何获取旧 Sprite 节点的位置以用于新 Sprite 节点?

ios - 有没有办法创建一个循环文件​​存储?就像 linux 中的 syslog

ios - 锁定旋转=iphone上的纵向,ipad没有锁定?

ios - SwiftUI 中的约束是什么?

iphone - 如何在 uitextview 中的任意光标位置插入文本?