大佬教程收集整理的这篇文章主要介绍了ios – Sprite Kit销接头似乎有一个不正确的锚点,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想要的设置是:一个宽,平的盒子和两个圆圈;圆圈通过SKPhysicsPinJoints连接到盒子,因此它们可以作为轮子.
- (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]; }
我期望的是针接头锚定在他们的中心点;然而,当我测试这个,关节的锚点似乎是远离的.
我错过了一些很明显的东西吗?
carNode.physicsBody = [SKPhysicsBody bodyWithRectangLeofSize:carNode.size]; carNode.position = CGPointMake(CGRectGetMidX(self.framE),CGRectGetMidY(self.framE));
将上述更改为
carNode.position = CGPointMake(CGRectGetMidX(self.framE),CGRectGetMidY(self.framE)); carNode.physicsBody = [SKPhysicsBody bodyWithRectangLeofSize:carNode.size];
应该工作谢谢Smick
以上是大佬教程为你收集整理的ios – Sprite Kit销接头似乎有一个不正确的锚点全部内容,希望文章能够帮你解决ios – Sprite Kit销接头似乎有一个不正确的锚点所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。