gpt4 book ai didi

compiler-errors - SpriteKit Swift3接触了SKNode

转载 作者:行者123 更新时间:2023-12-02 10:48:00 26 4
gpt4 key购买 nike

我正在尝试获取SceneKit中触摸位置的条件。我触摸SpriteKit对象,并编写该代码以获取SKnode对象:

class GameViewController: UIViewController , SCNSceneRendererDelegate {

var overlay: SKScene!

...

override public func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent!) {

for touch: AnyObject in touches {
let location: CGPoint = touch.location(in: overlay)
let touchedNode: SKNode = overlay.nodes(at: location

if(touchedNode.name == "WalkAnimationButton") {

self.tap()
}
else if(touchedNode.name == "CameraButton") {

sceneView.allowsCameraControl = true
}
else if(touchedNode.name == "WrenchButton") {

sceneView.showsStatistics = true
}
else if(touchedNode.name == "CharacterButton") {
if(currentCharacter < characterPaths.count-1) {
currentCharacter = currentCharacter+1
}
else{
currentCharacter = 0
}
}

}

self.setCharacterFromModelWithName(name: characterPaths[currentCharacter] as! NSString)
}

Xcode编写了我从未遇到过的错误:
无法将类型“[SKNode]”的值转换为指定的类型“SKNode”

最佳答案

要调用被触摸的节点,我们应该使用该代码:

let touchedNode: SKNode = overlay.atPoint(location)

因为我们调用SpriteKit对象的 名称,它用作SKNode类的成员。

关于compiler-errors - SpriteKit Swift3接触了SKNode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43305756/

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