我有一个名为“SpikyRedBall”的SKSpriteNode是一个红球.我想为它添加尖峰,所以我使用了以下代码.我可以看到Spike附着在球上但是当球与另一个球发生碰撞时,它不会考虑固定关节并将它们分开移动.我使用以下实现:
- @implementation SpikyRedBall
- -(instancetype) init
- {
- self = [super init];
- [self attachSpikes];
- return self;
- }
- -(void) attachSpikes
- {
- Spike *spike = [[Spike alloc] init];
- spike.position = CGPointMake(0,0);
- // attach the joint
- SKPhysicsJointFixed *ballAndSpikeJointFixed = [SKPhysicsJointFixed jointWithBodyA:self.physicsBody bodyB:spike.physicsBody anchor:CGPointZero];
- [self.scene.physicsWorld addJoint:ballAndSpikeJointFixed];
- [self addChild:spike];
- }
- @end