I am developing a game for tvOS in swift spritekit. There is a viewcontroller A which presents a SKScene B. I am forwarding the pressesBegan and pressesEnded from A to B.
pressesBegan is being called in A and forwarded to B but pressedEnded is not even called in A. Iam not getting why?
Below are the function implemented in A.
override func pressesEnded(presses: Set<UIPress>, withEvent event: UIPressesEvent?) {
if ((self.view as! SKView).scene?.isMemberOfClass(GameScene) == true){
let gameScene = (self.view as! SKView).scene as! GameScene
gameScene.pressesEnded(presses, withEvent: event)
}
}
override func pressesBegan(presses: Set<UIPress>, withEvent event: UIPressesEvent?) {
if ((self.view as! SKView).scene?.isMemberOfClass(GameScene) == true){
let gameScene = (self.view as! SKView).scene as! GameScene
gameScene.pressesBegan(presses, withEvent: event)
}
}
It looks like there's some sort of bug where
pressesEnded
doesn't get called in time. I noticed by putting a breakpoint onpressesEnded
andpressesBegan
. It always stops onpressesBegan
, but only stops onpressesEnded
after waiting a second to continue.The only workaround I could find was adding this in
viewDidLoad
:And then this:
That's swift 3 by the way.