Frist बंद, धन्यवाद आप प्रारंभिक वाहन कोड के लिए @Smick यहां पोस्ट के रूप में: Sprite Kit pin joints appear to have an incorrect anchorस्प्राइट किट - स्प्रिंग जोड़ों (झटका अवशोषक)
मैं पहिया के बीच एक स्लाइड संयुक्त जोड़ने के लिए कोशिश कर रहा हूँ (बाएं पहिया) और एक शॉक अवशोषण प्रभाव बनाने के लिए एक वसंत संयुक्त के साथ चेसिस।
नीचे दिए गए मेरे कोड के साथ, मुझे कोई संपीड़न नहीं मिलता है। मुझे एहसास है कि प्रलेखन एक वसंत संयुक्त को दो बोड खींचकर दिखाता है - जो मैं चाहता हूं उसके विपरीत। एसके में यह संभव है?
मुझे लगता है कि पिन संयुक्त अपराधी हो सकता है? जब मैं पिन संयुक्त को टिप्पणी करता हूं, तो कार के हिस्सों में गड़बड़ी होती है - सब कुछ स्क्रीन के चारों ओर उड़ता है। मूल रूप से, पिन संयुक्त ने चेसिस को पहिया पिन किया, लेकिन जाहिर है कि मैं पहिया को "सदमे अवशोषक" में पिन करना चाहता हूं।
इसके अलावा, SKPhysicsJointSliding के लिए "अक्ष" तर्क मुझे थोड़ा उलझन में डाल दिया है। यह एक वेक्टर चाहता है। एक वेक्टर के सापेक्ष?
अग्रिम धन्यवाद।
- (SKShapeNode*) makeWheel
{
SKShapeNode *wheel = [[SKShapeNode alloc] init];
CGMutablePathRef myPath = CGPathCreateMutable();
CGPathAddArc(myPath, NULL, 0,0, 16, 0, M_PI*2, YES);
wheel.path = myPath;
wheel.physicsBody.mass = 0.5;
return wheel;
}
- (void) createCar{
// 1. car body
SKSpriteNode *carBody = [SKSpriteNode spriteNodeWithColor:[UIColor whiteColor] size:CGSizeMake(120, 8)];
carBody.position = CGPointMake(200, 700);
carBody.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:carBody.size];
carBody.physicsBody.mass = 1.0;
[self addChild:carBody];
// 2. wheels
SKShapeNode *leftWheel = [self makeWheel];
leftWheel.position = CGPointMake(carBody.position.x - carBody.size.width/2, carBody.position.y-40);
leftWheel.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:16];
[self addChild:leftWheel];
SKShapeNode *rightWheel = [self makeWheel];
rightWheel.position = CGPointMake(carBody.position.x + carBody.size.width/2, carBody.position.y);
rightWheel.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:16];
[self addChild:rightWheel];
/* Build left shock absorber and attach wheel */
CGVector av =CGVectorMake(0.0, 5.0);
SKPhysicsJointSliding *leftSlide = [SKPhysicsJointSliding jointWithBodyA:carBody.physicsBody
bodyB:leftWheel.physicsBody
anchor:leftWheel.position
axis:av];
SKPhysicsJointSpring *leftSpring = [SKPhysicsJointSpring jointWithBodyA:carBody.physicsBody bodyB:leftWheel.physicsBody
anchorA:CGPointMake(carBody.position.x - carBody.size.width/2, carBody.position.y)
anchorB:leftWheel.position];
SKPhysicsJointPin *leftPin = [SKPhysicsJointPin jointWithBodyA:leftSpring.bodyA
bodyB:leftSpring.bodyB
anchor:leftWheel.position];
[self.physicsWorld addJoint:leftSlide];
[self.physicsWorld addJoint:leftSpring];
[self.physicsWorld addJoint:leftPin];
[self.physicsWorld addJoint:[SKPhysicsJointPin jointWithBodyA:carBody.physicsBody bodyB:rightWheel.physicsBody anchor:rightWheel.position]];
}