ios - SpriteKit : One node with two physics body

标签 ios objective-c sprite-kit

一个节点有可能有两条物理体路径吗?我想创建一个节点,节点两侧有两个(圆形)物理体。

如果不可能,是否有任何变通方法可以实现?谢谢

enter image description here

最佳答案

您想使用[SKPhysicsBody bodyWithBodies:...]。来自docs :

The shapes of the physics bodies passed into this method are used to create a new physics body whose covered area is the union of the areas of its children. These areas do not need to be contiguous. If there is space between two parts, other bodies may be able to pass between these parts. However, the physics body is treated as a single connected body, meaning that a force or impulse applied to the body affects all of the pieces as if they were held together with an indestructible frame.

它看起来像这样:

SKPhysicsBody *leftCircle = [SKPhysicsBody bodyWithCircleOfRadius:leftCircleRadius center:leftCircleCenter];
SKPhysicsBody *rightCircle = [SKPhysicsBody bodyWithCircleOfRadius:rightCircleRadius center:rightCircleCenter];

node.physicsBody = [SKPhysicsBody bodyWithBodies:@[leftCircle, rightCircle]];

关于ios - SpriteKit : One node with two physics body,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25178390/

相关文章:

iphone - 为 iPhone 编写 LaunchDaemon

ios - 如何在 Objective-C 中将 PHAsset 转换为 UIImage

objective-c - 使用 Core Data 生成的访问器的问题

swift - 如何在sprite-kit中的某些场景中展示广告?

iOS:请求访问相机

ios - 如何在 IOS 中创建允许直接跳转到设置屏幕的对话框

ios - 无法为 swift spritekit 背景设置完美图像

ios - 如果隐藏节点,如何禁用 SKSpriteNode 的 physicsBody?

objective-c - 如何将我的应用程序添加到 iphone/ipad 的设置中?

ios - MkmapView:如何在用户缩放时保持 map 居中