ios - SKSpriteNode 不受自定义 physicsBody 的重力影响

标签 ios objective-c sprite-kit cgpath skphysicsbody

我正在为 SKSpriteNode 的 physicsBody 创建自定义边缘路径。

CGMutablePathRef edgePath = CGPathCreateMutable();

CGPathMoveToPoint(edgePath, NULL, -100, -70);
CGPathAddLineToPoint(edgePath, NULL, -100, 40);
CGPathAddLineToPoint(edgePath, NULL, -80, -20);
CGPathAddLineToPoint(edgePath, NULL, 30, -20);
CGPathAddLineToPoint(edgePath, NULL, 100, 100);
CGPathAddLineToPoint(edgePath, NULL, 100, -70);
CGPathCloseSubpath(edgePath);

我尝试使用以下代码分配 physicsBody:

sprite.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromPath:edgePath];

sprite.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath:edgePath];

sprite.physicsBody = [SKPhysicsBody bodyWithEdgeChainFromPath:edgePath];

这些都不能使 Sprite 受到重力的影响。

但是,如果我使用一个简单的 bodyWithCircleOfRadius: Sprite 会受到重力的影响。

谁能解释为什么会发生这种情况?

最佳答案

边缘循环和链条创建静态(不可移动的)实体。它们不会受到重力的影响。

多边形物体应该受重力影响。但是,您必须确保多边形逆时针缠绕、不自相交并且其形状是凸的。否则结果不可预测。

关于ios - SKSpriteNode 不受自定义 physicsBody 的重力影响,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20217442/

相关文章:

objective-c - iOS UIImageView 流畅的图像呈现

objective-c - 从 Objective-C 中的图像读取非标准属性

swift - 找不到 SKTextureAtlas

ios - UIWebview 检测表单文本变化

ios - 在另一个类中调用函数的最佳方式是什么? ( swift )

ios - 如何在 Mapbox 中禁用用户位置注释的标注?

iphone - NSString stringWithFormat 很慢

iphone - Obj-C,dyld:找不到符号:_OBJC_CLASS _ $ _ NSUbiquitousKeyValueStore

swift SpriteKit : Use of unresolved identifier "player"?

ios - SpriteKit 物理在 iOS 9 上巨大的 FPS 下降