hpi-swa-teaching / GameMecha

A library providing implementations for common patterns in Squeak/Smalltalk game development.
MIT License
12 stars 2 forks source link

[GMKeyHandler] Add option to execute block/method only once per keystroke #73

Open tillprochaska opened 5 years ago

tillprochaska commented 5 years ago

Currently, blocks/methods registered to the key handler are executed repeatedly, if the user presses and holds the key. While this is a sensible behavior in some cases, it might be useful to add an option to limit this to a single execution per keystroke.

self gmRegisterToKeyHandler.

self
  gmRegisterBlock: [
    "`Hello` is printed only once, even if the user presses and holds the
     space bar for multiple `stepTime` intervals."
    Transcript show: 'Hello'.
  ]
  forKey: Character space
  once: true.

self
  gmRegisterRegisterMethodInvocation: handleKey
  on: self
  forKey: Character space
  once: true.