This site requires JavaScript, please enable it in your browser!
Greenfoot back
ftelliott
ftelliott wrote ...

2016/12/1

Using Arrow Keys to Move Specific Amounts

ftelliott ftelliott

2016/12/1

#
Hi Everyone We want to use the arrow keys to do something like this: if ( isKeyDown("left")) { set Location( getX() - 50, getY() ) }.... The problem is, depending on the game speed slider, the object moves varying amounts. It seems as if the keys are not "debounced"; meaning, it is acting as if the "left" key is being held down multiple times. We want it to just move once 50 pixels to the left for every *strike* of the key. We've tried an approach using getKey() without success. How are people accomplishing this? THANKS!
Super_Hippo Super_Hippo

2016/12/1

#
You could have a boolean field to save the state of the key and only if it is changing from not-pressed to pressed, you let it move.
You need to login to post a reply.