Listening for touches in GameScene
The SKScene
class (that GameScene
inherits from) includes handy functions we can use to monitor touch input. Follow these steps to wire up the GameScene
class:
In
GameScene.swift
, in thetouchesBegan
function, add this code at the very bottom to start thePlayer
flapping when the user touches the screen:Â Â Â Â Â Â Â player.startFlapping()
After
touchesBegan
, create two new functions in theGameScene
class. These functions stop the flapping when the user lifts his or her finger from the screen, or when an iOS notification interrupts the touch:Â Â Â Â Â Â Â override func touchesEnded(_ touches: Set<UITouch>, Â Â Â Â Â Â with event: UIEvent?) { Â Â Â Â Â Â player.stopFlapping() Â Â Â Â Â Â } Â Â Â Â Â Â override func touchesCancelled(_ touches: Set<UITouch>, Â Â Â Â Â Â with event: UIEvent?) { Â Â Â Â Â Â player.stopFlapping() Â Â Â Â Â Â }