gpt4 book ai didi

ios - 'SKNode ?' does not have a member named '位置'

转载 作者:行者123 更新时间:2023-11-28 09:17:39 25 4
gpt4 key购买 nike

我做错了什么?我似乎无法弄清楚这一点。我试过在后面放一个感叹号:var thisBlock = self.childNodeWithName(block),

这给了我一个新的错误说法。 type () 不确认协议(protocol)“BooleanType”。

func blockRunner() {
for(block, blockStatus) in self.blockStatuses {
var thisBlock = self.childNodeWithName(block)
if blockStatus.shouldRunBlock() {
blockStatus.timeGapForNextRun = random()
blockStatus.currentInterval = 0
blockStatus.isRunning = true
}

if blockStatus.isRunning {
if thisBlock.position.x = blockMaxX{
thisBlock.position.x -= CGFloat(self.groundSpeed)
} else {
thisBlock.position.x = self.origBlockPositionX
blockStatus.isRunning = false
self.score++
if ((self.score % 5) == 0) {
self.groundSpeed++
}
self.scoreText.text = String(self.score)
}
} else {
blockStatus.currentInterval++
}
}
}

最佳答案

childNodeWithName() 会返回一个可选的 SKNode?,您必须解包才能使用。我不知道为什么 var thisBlock = self.childNodeWithName(block)! 没有解决您的问题。我建议使用可选绑定(bind) (if let) 语法:

if let thisBlock = self.childNodeWithName(block) {
if blockStatus.shouldRunBlock() {
blockStatus.timeGapForNextRun = random()
blockStatus.currentInterval = 0
blockStatus.isRunning = true
}

if blockStatus.isRunning {
... rest of your code
}

如果没有子节点,这具有不会崩溃的额外优势。它只是不会进入 block 。

关于ios - 'SKNode ?' does not have a member named '位置',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26699486/

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