I am used to SpriteKit and just getting into SceneKit. Ive seen similar questions, all not quite what I am looking for. I can create a button in SpriteKit like this :
//setup the button
var oneButton = SKSpriteNode(imageNamed: "")
oneButton.name = "oneButton"
oneButton.position = CGPoint(x: -200, y: 400)
oneButton.zPosition = 8
oneButton.anchorPoint = CGPoint(x: 0.5, y: 0.5)
oneButton.size = CGSize(width: 150, height: 150)
addChild(oneButton)
//call the button
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first {
let location = touch.previousLocation(in: self)
let node = self.nodes(at: location).first
if node?.name == "oneButton" {
//when button tapped this code will happen
}
}
How would I go about doing something like this in SceneKit?
CodePudding user response:
You can keep doing what you are doing in SpriteKit! Make an SKScene
, add your buttons to it, then set that SKScene
as the SCNView
's overlaySKScene
:
yourScnView.overlaySKScene = yourSKSceneWithTheButtons