SpriteKit固定接头

joh*_*doe 8 ios sprite-kit

我有一个名为"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
Run Code Online (Sandbox Code Playgroud)

小智 1

为什么不将尖峰添加到精灵图像中呢?如果它们需要消失或脱落,您可以创建没有尖峰的图像的多个版本。