[英]SpriteKit Swift3 touched SKNode
I'm trying to get condition of touched location in SceneKit. 我想在SceneKit中获取触摸位置的条件。 I'm touching SpriteKit objects and wrote that code to get SKnode object: 我正在接触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 wrote that error which i've never faced before: Xcode编写了我以前从未遇到过的错误:
Cannot convert value of type '[SKNode]' to specified type 'SKNode' 无法将'[SKNode]'类型的值转换为指定类型'SKNode'
To call the touched node we should use that code: 要调用触摸的节点,我们应该使用该代码:
let touchedNode: SKNode = overlay.atPoint(location)
Because we calling name of SpriteKit object, which is using as member of SKNode class. 因为我们调用SpriteKit对象的名称 ,它正在用作SKNode类的成员。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.