How to use "arrow" keys on the keyboard as an interactive element. |
||
Although we can click on a sprite (and code the result with a "on mouseUp me" handler), we cannot key on a sprite. "Keying" on a sprite (unlike mouse-clicking on a sprite) really doesn't make sense. The sprite is "deaf" to the user tapping on keys. This means that you cannot put scripting for keystrokes in a script attached to a sprite. However, the Director movie itself IS hearing those keystrokes. Therefore, the way that you control the result is by testing for keystrokes in either one of 2 places:
No matter if you make a "movie" script or use the frame script, you write the Lingo code in the same way. Here I am going to assume that you are putting it in your frame script: If you want VERY responsive arrow keys put this in the same script window as your frame script. (Overwrite the script that is already there with this new script). When you run the movie hold down the arrow key (don't just tap on it). on exitFrame me Remember that the higher the number that you add or subtract from the location value (locV, locH), the faster things go. If you want a LESS responsive arrow key try this next version. Again, when you run the movie hold down the arrow key (don't just tap on it).: on exitFrame me on keydown me The keycode is used because that is the only way to identify arrow keys. You could use letter keys to make your sprite move. Then you could write something like: if the key = "a" then ... etc. etc. The arrow keys are good because they literally point in directions that you want your sprites to move. But other keys could be substituted. The Lingo Dictionary, available in the Help menu, can give you more info as you need it. |
||