dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Key problem for Games

  1. #1
    Hi there,

    is it possible to detect if a special key is "NOT" pressed?
    I know about "if(Key.isDown("keycode") {" , but there is no kind of "if(Key.isUp...." .

    As far as I know there is that toggle function, but I dont toggle the key, just want to have any function if a special key isn«t pressed anymore.

    U know?

    For example: The is a character that walks from left to right and reverse, if I use the cursor-keys (left/right).
    if I don«t press any cursor key the character stops, cause the movement is driven by Key.isDown(...).
    but I want to let the character use another pose when he doesn«t walk and so I need any kind of query, if the cursor keys aren«t pressed anymore.

    Any suggestions how to solve this ****ty problem?


    Manuel

  2. #2
    Senior Member stoc's Avatar
    Join Date
    Nov 2001
    Location
    Romania, Arad
    Posts
    428
    U can set a variable ...to say key_pressed=false

    if(Key.isDown("keycode")){
    key_pressed=false
    }else{
    key_pressed=false
    }

    ...
    ...
    ...

    if (key_pressed==false){
    //// your event
    }

  3. #3
    Senior Member stoc's Avatar
    Join Date
    Nov 2001
    Location
    Romania, Arad
    Posts
    428
    sorry...
    if(Key.isDown("keycode")){
    key_pressed=true /////// here was the error....:$
    }else{
    key_pressed=false
    }

  4. #4
    ********* mentuat's Avatar
    Join Date
    Mar 2002
    Location
    out of office
    Posts
    718
    or you could put elseif 's between the key.isdown commands, with the last else being used when no key's are being presed

  5. #5
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749

    The NOT operator

    Use the ! not operator:

    Key.isDown("keycode") = Key is down
    !Key.isDown("keycode") = Key is up

    Basic notation.

  6. #6
    Hey Folks,

    the !(NOT)Operator works fine!!!

    Thanx for the tip,
    also big thanx to all who have posted suggestions here!
    You are great!

    Manuel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center