スプライトキットのピンジョイントをテストしています。スプライトキットのピンジョイントのアンカーが正しくないようです
希望する設定は、1つのワイドフラットボックスと2つのサークルです。円はSKPhysicsPinジョイントを介してボックスに接続されているため、ホイールとして機能することができます。
ここに私のコードです。私はそれをできるだけ簡潔にするために試してみた:
- (SKNode*) createWheelWithRadius:(float)wheelRadius {
CGRect wheelRect = CGRectMake(-wheelRadius, -wheelRadius, wheelRadius*2, wheelRadius*2);
SKShapeNode* wheelNode = [[SKShapeNode alloc] init];
wheelNode.path = [UIBezierPath bezierPathWithOvalInRect:wheelRect].CGPath;
wheelNode.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:wheelRadius];
return wheelNode;
}
- (void) createCar {
// Create the car
SKSpriteNode* carNode = [SKSpriteNode spriteNodeWithColor:[SKColor yellowColor] size:CGSizeMake(150, 50)];
carNode.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:carNode.size];
carNode.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
[self addChild:carNode];
// Create the left wheel
SKNode* leftWheelNode = [self createWheelWithRadius:30];
leftWheelNode.position = CGPointMake(carNode.position.x-80, carNode.position.y);
[self addChild:leftWheelNode];
// Create the right wheel
SKNode* rightWheelNode = [self createWheelWithRadius:30];
rightWheelNode.position = CGPointMake(carNode.position.x+80, carNode.position.y);
[self addChild:rightWheelNode];
// Attach the wheels to the body
CGPoint leftWheelPosition = leftWheelNode.position;
CGPoint rightWheelPosition = rightWheelNode.position;
SKPhysicsJointPin* leftPinJoint = [SKPhysicsJointPin jointWithBodyA:carNode.physicsBody bodyB:leftWheelNode.physicsBody anchor:leftWheelPosition];
SKPhysicsJointPin* rightPinJoint = [SKPhysicsJointPin jointWithBodyA:carNode.physicsBody bodyB:rightWheelNode.physicsBody anchor:rightWheelPosition];
[self.physicsWorld addJoint:leftPinJoint];
[self.physicsWorld addJoint:rightPinJoint];
}
私は期待していどのようなピン継手は、その中心点に固定されていることです。しかし、私がこれをテストすると、関節のアンカーは遠く離れているように見えます。
本当に明白なものがありませんか?
あなたのTVCでは、numberOfSectionsInTableViewをコメントアウトし、numberOfRowsInSectionには[_dataSourceArray count]を使用するだけです。良い例ですが、[head.physicsBody applyTorque:0.2]を追加する必要があります。固定ジョイントとの違いを実際に表示するためにピン結合に移動します。良い仕事 - 分かち合いに感謝します。 – DogCoffee
ありがとうSmick ..私は例を更新しました。しかし、TVCはそのようにコーディングされています。なぜなら、2つのセクションがあるからです。あなたの車の例をジョイントタイプとして追加できませんでした。 :)その例は別のセクションに置かれます。 – Bavan
私はここの例で車を見ることはできませんが、まだ関節のリストしか持っていません。私はすべてのテストコードをTVCに入れます - クールなアイデア! – DogCoffee