0

I am writing a game for Mac OS in Swift 3 with SpriteKit and GameplayKit. I already have created a method to capture keyboard press events and can control my character on the map. Sprite is moving using MovementComponent which is applying movement action on every Update if a keyboard event is recorded. However there is a delay in character movement right after the first key press. The moment I press and hold an arrow key my character moves for the duration of the standard movement action but then there is a delay before it continues to move as there is about .5 delay before keyboard will start repeat cycle after the first keypress. My question is: how can I change the keyboard repeat rate or remove this delay while my game is running or is there a better way to implement continuous movement controlled via keyboard in a mac game?

Thank you all in advance.

Léo Natan
  • 56,823
  • 9
  • 150
  • 195
  • 2
    What does "Swift 3" have to do with keyboard events in your game? It is already clearly stated by the tags that you are using Swift, but this is a framework use question. – Léo Natan Oct 21 '16 at 16:35
  • Repeat rate is usually defined in an OS, I am not sure of any app that changes this. I would be monitoring key down and key up events, and just use something like `NSTimer` if you need to poll outside of your sprite kit time, or use the update method if needed in Sprite Kit time, to check the state of the key (Up / down) and handle accordingly – Knight0fDragon Oct 21 '16 at 16:39
  • Thank you for your comments. I am new to this and may not be very sharp in terminology. I will try suggested solutions. – Alex Kreston Oct 22 '16 at 04:03

1 Answers1

1

This is perhaps best thought of in terms of pseudo code.

While key is pressed, do such-and-such

In this way you can be independent of the system's polling and reporting of a held key press.

Confused
  • 6,048
  • 6
  • 34
  • 75