Pong | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

9th Aug 2018, 4:25 PM
gamer fox
gamer fox - avatar
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) } }
8th Oct 2018, 5:22 PM
Zach Eriksen
Zach Eriksen - avatar