Xcode Spritekit分数自身相乘

Xcode Spritekit分数自身相乘,xcode,swift,Xcode,Swift,游戏的分数组件运行正常,但最近我实现了GameKit,它增加了比代码中更多的分数 else if key == kCollectableStarKey { sprite = Collectable(texture: atlas.textureNamed("StarGold")) (sprite as! Collectable).collectionSound = Sound(named: "Collect.caf") (sprit

游戏的分数组件运行正常,但最近我实现了GameKit,它增加了比代码中更多的分数

        else if key == kCollectableStarKey {
        sprite = Collectable(texture: atlas.textureNamed("StarGold"))

        (sprite as! Collectable).collectionSound = Sound(named: "Collect.caf")
        (sprite as! Collectable).pointValue = 3
        (sprite as! Collectable).delegate = self.delegate

        sprite.physicsBody = SKPhysicsBody(circleOfRadius: sprite.size.width * 0.3)
        sprite.physicsBody?.categoryBitMask = kCollectableCategory
        sprite.physicsBody?.dynamic = false

        self.addChild(sprite)
    }

    else if key == kBoneKey {


        sprite = Collectable(texture: atlas.textureNamed("FishBone"))


        (sprite as! Collectable).collectionSound = Sound(named: "fail.caf")
        (sprite as! Collectable).pointValue = -2
        (sprite as! Collectable).delegate = self.delegate


        sprite.physicsBody = SKPhysicsBody(circleOfRadius: sprite.size.width * 0.3)
        sprite.physicsBody?.categoryBitMask = kCollectableCategory
        sprite.physicsBody?.dynamic = false

        self.addChild(sprite)
    }
这是可收集的协议

    protocol CollectableDelegate {

    func wasCollected(collectable: Collectable)

}

class Collectable: SKSpriteNode {

    var delegate: CollectableDelegate!
    var collectionSound: Sound!
    var pointValue: Int = 0

    func collect() {
        self.collectionSound.play()
        self.runAction(SKAction.removeFromParent())
        if let delegate = self.delegate {
            self.delegate.wasCollected(self)
        }
    }

}
骨协议:

protocol BoneDelegate {

    func wasGathered(collectable: boneCollectable)

}

class boneCollectable: SKSpriteNode {

    var delegate: BoneDelegate!
    var gatherSound: Sound!
    var boneValue: Int = 0

    func gather() {
        self.gatherSound.play()
        self.runAction(SKAction.removeFromParent())
        if let delegate = self.delegate {
            self.delegate.wasGathered(self)
        }
    }

}
我也上传了一段关于这个问题的视频:
看来问题出在我的主精灵的物理身体上

    // Setup physics body with path.
    let offsetX = self.frame.size.width * self.anchorPoint.x;
    let offsetY = self.frame.size.height * self.anchorPoint.y;
    var planeBodyPath = CGPathCreateMutable();
    CGPathMoveToPoint(planeBodyPath, nil, 19 - offsetX, 0 - offsetY);
    CGPathAddLineToPoint(planeBodyPath, nil, 40 - offsetX, 50 - offsetY);
    CGPathAddLineToPoint(planeBodyPath, nil, 14 - offsetX, 40 - offsetY);
    CGPathAddLineToPoint(planeBodyPath, nil, 38 - offsetX, 11 - offsetY);
    CGPathAddLineToPoint(planeBodyPath, nil, 11 - offsetX, 20 - offsetY);
    CGPathAddLineToPoint(planeBodyPath, nil, 5 - offsetX, 20 - offsetY);
    CGPathAddLineToPoint(planeBodyPath, nil, 36 - offsetX, 28 - offsetY);
    CGPathAddLineToPoint(planeBodyPath, nil, 20 - offsetX, 27 - offsetY);
    CGPathAddLineToPoint(planeBodyPath, nil, 20 - offsetX, 7 - offsetY);
    CGPathAddLineToPoint(planeBodyPath, nil, 54 - offsetX, 13 - offsetY);
    CGPathAddLineToPoint(planeBodyPath, nil, 70 - offsetX, 31 - offsetY);
    CGPathAddLineToPoint(planeBodyPath, nil, 70 - offsetX, 40 - offsetY);
    CGPathAddLineToPoint(planeBodyPath, nil, 69 - offsetX, 55 - offsetY);



    CGPathCloseSubpath(planeBodyPath);
    self.physicsBody = SKPhysicsBody(polygonFromPath: planeBodyPath)
删除此项并添加此项后:

    // Setup physics body with path.
    let offsetX = self.frame.size.width * self.anchorPoint.x;
    let offsetY = self.frame.size.height * self.anchorPoint.y;
    var planeBodyPath = CGPathCreateMutable();

    CGPathMoveToPoint(planeBodyPath, nil, 64 - offsetX, 11 - offsetY);
    CGPathAddLineToPoint(planeBodyPath, nil, 77 - offsetX, 42 - offsetY);
    CGPathAddLineToPoint(planeBodyPath, nil, 75 - offsetX, 10 - offsetY);
    CGPathAddLineToPoint(planeBodyPath, nil, 38 - offsetX, 30 - offsetY);
    CGPathAddLineToPoint(planeBodyPath, nil, 11 - offsetX, 54 - offsetY);
    CGPathAddLineToPoint(planeBodyPath, nil, 5 - offsetX, 57 - offsetY);
    CGPathAddLineToPoint(planeBodyPath, nil, 36 - offsetX, 61 - offsetY);
    CGPathAddLineToPoint(planeBodyPath, nil, 76 - offsetX, 27 - offsetY);
    CGPathAddLineToPoint(planeBodyPath, nil, 74 - offsetX, 7 - offsetY);
    CGPathAddLineToPoint(planeBodyPath, nil, 54 - offsetX, 13 - offsetY);
    CGPathAddLineToPoint(planeBodyPath, nil, 14 - offsetX, 31 - offsetY);
    CGPathAddLineToPoint(planeBodyPath, nil, 27 - offsetX, 62 - offsetY);
    CGPathAddLineToPoint(planeBodyPath, nil, 69 - offsetX, 55 - offsetY);

    CGPathCloseSubpath(planeBodyPath);
    self.physicsBody = SKPhysicsBody(polygonFromPath: planeBodyPath)
所有人都在评分系统中正常工作。然而,我不知道它为什么会导致错误