Arrow Keys to control movement of a Morph

Alexander Lazarević Alexander at Lazarevic.de
Mon Jul 5 06:58:22 UTC 2004


Hi Milan,

Look at an existing game by loading it with the PackageLoader from 
SqeakMap. Sokoban for example uses the arrow keys to move a morph 
around. There you will find this methods, which should you get started:

*handlesKeyboard: aMorphicEvent
    ^ true

*and

*keyStroke: aKeyboardEvent
    | char |
    char := aKeyboardEvent keyCharacter.
    char = Character arrowLeft ifTrue: [^ self moveLeft].
    char = Character arrowRight ifTrue: [^ self moveRight].
    char = Character arrowUp ifTrue: [^ self moveUp].
    char = Character arrowDown ifTrue: [^ self moveDown].
    char asLowercase = $a ifTrue: [^ self again].
*         [...]

Alex



More information about the Squeak-dev mailing list