Wednesday, December 9, 2009

Movement

Today I worked more with the morph adding keyboard input for motion. So far (for a reason im not quite sure of) the tutorial has had me limit the motion of the morph so that it only responds to the keyboard input if the mouse is hovering over the morph. The method for the motion follows:

handleKeystroke: anEvent
| keyValue |
keyValue := anEvent keyValue.
keyValue = 30 "up arrow"
ifTrue: [self position: self position -- (0 @ 1)].
keyValue = 31 "down arrow"
ifTrue: [self position: self position + (0 @ 1)].
keyValue = 29 "right arrow"
ifTrue: [self position: self position + (1 @ 0)].
keyValue = 28 "left arrow"
ifTrue: [self position: self position -- (1 @ 0)]

I also learned how to check the values of each key by opening a Transcript and in a workspace preforming:

Transcript show: anEvent keyValue

No comments:

Post a Comment