3

这似乎是 Apple 的一个重大疏忽,但由于 SKPhysicsJoints 的锚点设置在场景坐标中,这使得任何类型的滚动游戏都变得不可能。

要在 SpriteKit 中模拟相机,您需要创建一个包含所有游戏元素的 WorldNode,然后在场景中平移。不幸的是,这样做会导致游戏中每个对象的场景坐标在您平移世界时每帧都发生变化。反过来,这打破了联合锚点,事情变得疯狂。

甚至没有办法改变关节的锚点,所以我什至没有办法只更新每一帧的坐标。在滚动游戏中使用 SKPhysicsJoint 似乎不是一种选择。

有谁知道解决这个问题的方法?

4

1 回答 1

3

Ok, I think I figured out what was going on, and I was totally incorrect in my original assumption. The reason my anchor points looked incorrect is because the [convertPoint toNode] call was returning me Scene coordinates that were incorrect. After several hours I realized it was off by exactly half the screen dimensions. My Scene has an anchorPoint of (0.5, 0.5), but this screws up the conversion values. So, if I simply offset the point by width/2, height/2 it's correct:

GPoint pt = CGPointMake(anchorWorldX, anchorWorldY);
pt = [gGameScene convertPoint:pt fromNode:gGameWorld]; // convert to scene coords, but it's WRONG

pt.x += scene.size.width * scene.anchorPoint.x;   // this properly adjusts the value to be correct
pt.y += scene.size.height * scene.anchorPoint.y;

SKPhysicsJointPin* pin =[SKPhysicsJointPin jointWithBodyA:hinge.physicsBody bodyB:door.physicsBody anchor:pt];
于 2014-07-09T23:13:18.967 回答