3 Replies Latest reply on Aug 21, 2008 2:34 AM by Mikael(swe)

    Simple keydown, not working as I want.

    Mikael(swe)
      Hi all,

      Hope someone can help me with what I hope has a simple solution. I've been making a lot of games with Director 10, but now I'm making a game, using Director 11 and I cannot get the key.keyPressed work the way I want.

      The thing is that I want to move a sprite from left to right when the user either presses left or right arrow. The problem is that if I use:

      -- Loop script --
      on enterFrame(me)
      keyDownScript = testKey()
      end

      -- Movie script --
      on testKey()
      if (_key.keycode = 123) then -- left
      put "left"
      end if
      if (_key.keycode = 124) then -- right
      put "right"
      end if
      end
      ---------

      If the user doesn't press any key at all, Director still thinks that a key is pressed.

      And if I try this in the movie script, instead of using the previous example:

      on keyDown
      case (_key.keyCode) of
      123: put "TurnLeft"
      126: put "GoForward"
      125: put "BackUp"
      124: put "TurnRight"
      end case
      end keyDown

      The first second the user press a button it lags. For example, I the user press the left arrow and hold it down, it will take a while for Director to recognize that the arrow is held down.

      Any ideas?

      Thanks,
      Mikael