This content has been marked as final. Show 4 replies
There are a few different ways you can do it:
1. Check for #keyDown events
2. Check, on every #exitframe, what keys are currently pressed using KeyPressed()
3. Use the 'keyDownScript'
To respond to Keydown events, you need to remember that #keyDown events are only sent to certain sprite types (editable text etc). If your tiles are bitmaps, they probably wont receive #keyDown. In this case, using a frame script like this might help
on keyDown (me)
k = the key
With the second approach, you would add a behaviour like this onto each of the individual tile sprites:
on exitframe (me)
if keyPressed(thekeythatIamInterestedIn) then
With the third approach, you would do something like this
the keyDownScript = "MyKeyControlScript"
on MyKeyControlScript ()
k = the key
Another trick that's useful if you want to have dual keyboard and mouse
controls: Set up your mouseUp commands as normal, then in the frame script
or whatever, you can have a bit that goes like:
if keyPressed("A") then sprite(X).mouseUp()
This will cause the sprite(X) to recieve a mouseUp event when you press the
'A' key, just as if you'd clicked the sprite with the mouse. That way if
you want a mouse click and a keyboard shortcut to do the same thing, you
don't have to duplicate code. Just set it up on the mouse and simulate a
mouseclick when the relevant key is pressed.
Thanks for the pointers Luke. I've tried the various codes and the best I can manage is getting the relevant sprite to move on one keyDown. When I try it for the next letter/sprite nothing happens. I'll give it another go and see what I can come up with...
Thx for the lingo pointer Darrel. Your lingo seems straight forward but after over-coming some handler code errors, the movie plays but nothing happens on the keystroke. I'll speak with my lecturer on the code and see what we can come up with...