0
我試圖在spritekit中創建一個pendalum,但我無法弄清楚如何使pendalum擺動。到目前爲止的代碼是:如何用spritekit創建擺錘
transparentpixel = [SKSpriteNode spriteNodeWithImageNamed:@"transparent_pixel"];
[transparentpixel setPosition:CGPointMake(150,150)];
transparentpixel.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(1, 1)];
transparentpixel.physicsBody.dynamic = YES;
[_bg addChild:transparentpixel];
pendalum = [SKSpriteNode spriteNodeWithImageNamed:@"pendalum_image"];
[pendalum setPosition:CGPointMake(150,120)];
pendalum.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:pendalum.size];
pendalum.physicsBody.dynamic = YES;
[_bg addChild:pendalum];
CGPoint pendalumjointanchor = CGPointMake(150,150);
SKPhysicsJointPin *pendalumJointPin = [SKPhysicsJointPin jointWithBodyA:transparentpixel.physicsBody bodyB:pendalum.physicsBody anchor:pendalumjointanchor];
[self.physicsWorld addJoint:pendalumJointPin];
我無法弄清楚如何使pendalum擺動不確定。
您是否嘗試過對擺錘施力? AFAIK Sprite Kit沒有關節的電動力。而FYI則不需要透明像素精靈節點來錨定關節,只需創建一個普通的SKNode作爲針的不可見錨。這將會更有效率。 – LearnCocos2D 2014-09-03 11:54:36
我如何對Pendalum施力?如果透明像素的動態屬性設置爲NO,則可以使用rotateToAngle SKAction左右擺動pendalum。如果我將它設置爲YES,則Pendalum不會擺動。它只是左右旋轉。不知何故,我必須使透明像素爲靜態,以便只有Pendalum圖像的底部擺動。 – Sakis 2014-09-03 12:48:34
行動不移動物理機構,這意味着他們不施加力量的身體。對於一個物理機構來說,所有的動作都應該通過力量/衝動/速度來完成,而不是動作。請參閱:https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKPhysicsBody_Ref/Reference/Reference.html#//apple_ref/occ/instm/SKPhysicsBody/applyImpulse: – LearnCocos2D 2014-09-03 17:47:46