+ 1
Pong
hi I'm a beginner at xcode and I'm making a simple pong game but the tutorial I'm watching was making it for iOS and I need it on MacOS, everything worked fine but then the input part I needed to make the arrow keys move the pong but I found nothing in the internet please tell me how to make arrow keys move sprites left and right
1 Answer
+ 1
Hey Gamer Fox!
You can use the keyDown and keyUp methods!
For example:
override func keyDown(with event: NSEvent) {
switch event.keyCode {
case 0: player.turn(.left) // A
case 2: player.turn(.right) // D
default:
print(event.keyCode)
}
}
override func keyUp(with event: NSEvent) {
switch event.keyCode {
case 0: player.turn(.left)
case 2: player.turn(.right)
default:
print(event.keyCode)
}
}