gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 22:21:42 24 4
gpt4 key购买 nike

我正在为 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/

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