観覧車を作ろうとしています。土台(脚)、胴体(回転する円形のパーツ)、座(全部で16個)の3種類のスプライトで構成されています。
以下のコードでは、ベースをシーンに追加し、ベースにボディを取り付け、最後に各シートをボディに取り付けています。座席は現在、体と一緒に(奇妙な方法で)回転しています。シートを回転させたくありません。私は何を間違っていますか?
注: @dragoneye からのコメントと提案で更新
-(void) initFerrisWheel {
self.physicsWorld.gravity = CGVectorMake(0, 0);
//creates the body of the ferris wheel and attaches it to the base
SKSpriteNode *ferrisWheel = (SKSpriteNode*)[self childNodeWithName:@"ferriswheel_base"];
SKTexture *bodyTexture = [[SharedAssetsManager sharedData].menuAssets objectForKey:@"ferriswheel_body"];
SKSpriteNode *body = [[SKSpriteNode alloc] initWithTexture:bodyTexture];
[body setZPosition:2];
[body setPosition:CGPointMake(0, 55)];
body.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:self.size.height/2];
[ferrisWheel addChild:body];
//rotates the body of the ferris wheel
SKAction *rotateSequence = [SKAction rotateByAngle:-0.785 duration:2.0];
SKAction *rotateFinal = [SKAction repeatActionForever:rotateSequence];
[body runAction:rotateFinal];
SKTexture *seatTexture = [[SharedAssetsManager sharedData].menuAssets objectForKey:@"ferriswheel_seat"];
int r = 130; //radius of the body for the ferris wheel
for (int i = 0; i < 16; i++) {
//creates a seat and places it on the body
SKSpriteNode *seat = [[SKSpriteNode alloc] initWithTexture:seatTexture];
float x = r * cosf(2*M_PI*i/16);
float y = r * sinf(2*M_PI*i/16);
[seat setPosition:CGPointMake(x, y)];
[seat setZPosition:3];
[body addChild:seat];
//physics body stuff
seat.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:seat.size.height/2];
seat.physicsBody.dynamic = YES;
CGPoint anchor = CGPointMake(x, y);
SKPhysicsJointPin *pin = [SKPhysicsJointPin jointWithBodyA:body.physicsBody bodyB:seat.physicsBody anchor:anchor];
[self.physicsWorld addJoint:pin];
pin.shouldEnableLimits = YES;
pin.lowerAngleLimit = -0.25;
pin.upperAngleLimit = 0.25;
}
}