Note:
Prior to asking this question I have viewed and attempted solutions posted for the following questions:
Context:
I have implemented a basic game menu for my game following the example set here.
When I reach the GameScene
I would like to have a UIGestureRecognizer
that when the screen is swiped up, opens a pause menu. However prior to focusing on the implementation of the pause menu, I foremost need this UIGestureRecognizer
to work.
In my GameScene
, I have added a function:
func swipedUp(_ sender: UISwipeGestureRecognizer){
print("up")
}
and inside override fund didMove(to view: SKView)
:
let swipeUpRecognizer:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(self.swipedUp(_:)))
swipeUpRecognizer.direction = .up
view.addGestureRecognizer(swipeUpRecognizer)
This does not work. For the first line (starts with let
) I have tried several variants such as:
let swipeUpRecognizer:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipedUp"))
let swipeUpRecognizer:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipedUp:"))
as well as variations to the swipedUp
function, e.g.
func swipedUp(receiver: UISwipeGestureRecognizer){
print("up")
}
Question
How to add a simple UIGestureRecognizer
to only one SKView
. I specify one, as due to the implementation of the menu, all the SKView
s share the same GameViewController
. Further, the GameScene
is created only when reached via the menu, and destroyed after the game is over (so making the GameScene
a global variable will not work either).