gpt4 book ai didi

xcode - Spritekit 分数 self 倍增

转载 作者:行者123 更新时间:2023-11-30 14:17:09 27 4
gpt4 key购买 nike

游戏的分数组件运行正常,但最近我实现了 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)

    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):

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)
}
}

}

我还上传了有关该问题的视频: Video here

最佳答案

看来问题出在我的主要 Sprite 的物理主体上。

    // 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)

评分系统一切正常。但是我不知道为什么它会导致错误。

关于xcode - Spritekit 分数 self 倍增,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30993857/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com