I have been working on some code that uses a button to call a scene. However it won't work on my IPad and I think I may have done a few things wrong, would anyone be willing to tell me how to get it to work. Here is my code:
import SpriteKit
import UIKit
import PlaygoundSupport
class ButtonNode: SKSpriteNode {
var action: ((ButtonNode) -> Void)?
var isSelected: Bool = false{
didSet{
alpha = isSelected ? 0.8 : 1
}
}
required init(coder: NSCoder){
fatalError("NSCoding not supported")
}
init(texture: SKTexture, size: CGSize){
super.init(texture: texture, color: SKColor.white, size:size)
isUserInteractionEnabled = true
}
override func touchesBegan(with event: NSEvent){
action?(self)
}
override func mouseDown(with event: NSEvent){
action?(self)
}
}
class GameScene: SKScene{
override func didMove(to view: SKView){
}
}
let scene = GameScene(size: CGSize(width: 400, height: 640)
scene.scaleMode = .aspectFill
scene.backgroundColor = .gray
let view = SKView(frame: CGRect(x:0, y:0, width: scene.size.width, height: scene.size.height))
view.presentScene(scene)
PllygroundPage.current,liveView = view
start button = ButtonNode(texture: SKTexture(imageNamed: "start-button"), size: CGSize(width:184, height: 72))
startButton.position = CGPoint(x: 0.0, y: 0.0)
startButton.action = { (button) in
if let scene = IntroCutScene(fileNamed: "IntroCutScene"){
self.scene!.scaleMode = .aspectFill
GameVariables.sceneView.presentScene(scene, transition: SKTransition.moveIn(with: SKTransitionDirection.right, duration: 2.5))
}
}
self.addChild(startButton)
the error message that shows up is: use of undeclared type 'NSEvent'