ios - SpriteKit PhysicsWorld 坐标系,奇怪的运行时关节 anchor
<p><p>这里有两个可能相关的事情:</p>
<p>1) 我可以使用 self、self.scene 和 myWorld 从我的 SKScene 执行文件中绘制一个框并添加到子节点,但不能使用 SKSprite 节点的场景属性。 </p>
<pre><code>SKSpriteNode *bla = size:CGSizeMake(100, 100)];
; // If I use bla.scene, it doesn't work. self, self.scene, myworld all do work though.
bla.position = CGPointMake(0, 0);
bla.zPosition = 999;
</code></pre>
<p>2) 我看过相关问题 <a href="https://stackoverflow.com/questions/19343459/spritekit-how-to-create-basic-physics-joints" rel="noreferrer noopener nofollow">here</a>和 <a href="https://stackoverflow.com/questions/19342417/sprite-kit-pin-joints-appear-to-have-an-incorrect-anchor" rel="noreferrer noopener nofollow">here</a> ,但我试图在游戏过程中添加一个关节(捕获一根绳子)。在 `didBeginContact: 中进行一些排序后调用此方法:</p>
<pre><code>-(void)monkey:(SKPhysicsBody *)monkeyPhysicsBody didCollideWithRope:(SKPhysicsBody *)ropePhysicsBody atPoint:(CGPoint)contactPoint
{
if (monkeyPhysicsBody.joints.count == 0) {
// Create a new joint between the player and the rope segment
CGPoint convertedRopePosition = ;
SKPhysicsJointPin *jointPin = ;
jointPin.upperAngleLimit = M_PI/4;
jointPin.shouldEnableLimits = YES;
;
}
}
</code></pre>
<p>我在场景中启用了 <code>showPhyiscs</code>,所以我可以看到关节最终会出现在一个完全古怪的地方。不幸的是,我不知道如何应用链接的解决方案,因为我没有在此方法中添加 <code>SKSpriteNodes</code>,它们已经存在,所以我不能只是翻转 <code>position 的顺序</code> 和 <code>physicsBody</code>.</p>
<p>我已经尝试了两种 <code>convertPoint</code> 方法的所有排列。没有任何效果。我最好的猜测是 <code>physicsWorld</code> 正在使用一些古怪的坐标系。 </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>与位置 (<em>CGPoint</em>) 或帧 (<em>CGRect</em>) 相关的 <strong>SKPhysicsWorld</strong> 方法成员将位于场景坐标中。场景坐标引用点 {0,0} 作为左下角,并且在整个 <strong>SpriteKit</strong> 中保持一致。</p>
<p>当 <strong><em>bla 时,名为 <strong><em>bla</em></strong> 的对象的 <strong>scene</strong> 属性将为 <strong>nil</strong> </em></strong> 是首先创建的,并在添加到场景时由场景设置。</p>
<pre><code>; // this won't do anything as scene will be nil when first created
</code></pre>
<p>看起来好像 <strong>convertedRopePosition</strong> 被分配了不正确的值,因为您传递到的第二个成员 <strong>- (CGPoint)convertPoint:(CGPoint)point fromNode:(SKNode *)节点</strong> ,当它应该是与 <em>此节点</em> 相同的节点树中的另一个节点时的场景。其中 <em>此节点</em> 是调用者(在本例中为 <strong>SKScene</strong> 子类)。</p>
<p>换行试试-</p>
<pre><code>CGPoint convertedRopePosition = ;
</code></pre>
<p>与-</p>
<pre><code>CGPoint convertedRopePosition = ;
</code></pre></p>
<p style="font-size: 20px;">关于ios - SpriteKit PhysicsWorld 坐标系,奇怪的运行时关节 anchor ,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/27199200/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/27199200/
</a>
</p>
页:
[1]