Is there a way to have Swift 2 recognize you are pressing the up arrow, down arrow, left arrow, and right arrow without having to use "Apple key codes" (if you Google that phrase it is the first hit) so here is a working code, but I would like to not have to use numbers to identify each key:
override func keyDown(keyEvent: NSEvent) {
/
let code = keyEvent.keyCode
if code == 126{
for ball in ballArray{
ball.physicsBody?.applyForce(CGVector(dx: 0, dy: 1000))
}
}
if code == 125{
for ball in ballArray{
ball.physicsBody?.applyForce(CGVector(dx: 0, dy: -1000))
}
}
if code == 124{
for ball in ballArray{
ball.physicsBody?.applyForce(CGVector(dx: 1000, dy: 0))
}
}
if code == 123{
for ball in ballArray{
ball.physicsBody?.applyForce(CGVector(dx: -1000, dy: 0))
}
}
if code == 49{
for ball in ballArray{
ball.removeFromParent()
}
ballArray = Array<SKSpriteNode>()
}
}
I was hoping to also find a way for the spacebar to be used without having to use the arbitrary key codes.