我试图在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写了我之前从未遇到过的错误:
无法转换类型&#39; [SKNode]&#39;的值指定类型&#39; SKNode&#39;
答案 0 :(得分:0)
要调用触摸的节点,我们应该使用该代码:
{{1}}
因为我们调用了SpriteKit对象的名称,它正在用作SKNode类的成员。