macOS SpriteKit Diagonal Sprite Movement

Hi! I am working on a SpriteKit project for macOS that involves using the WASD keys to move a sprite onscreen. An issue I'm having is that I cannot seem to detect two keys being pressed simultaneously, in order to create diagonal movement. For example, I'd like for W to move the sprite upwards, but W+D to move diagnally upwards in a 'northeast' direction. Currently, I'm overriding keyDown, but I undserstand that each individual key press is one event, so this won't really work. How would I efficiently detect multiple keys being pressed down? Thanks!

Accepted Reply

Try using the keyUp as well, so you can test when keys are released too. If you know that two keys are currently down (and neither has been released back up again) you should be able to do your diagonal movement from that.

Replies

Try using the keyUp as well, so you can test when keys are released too. If you know that two keys are currently down (and neither has been released back up again) you should be able to do your diagonal movement from that.