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

2016/10/27

isKeyDown

Nosson1459 Nosson1459

2016/10/27

#
is there any method that checks if the the key was released
danpost danpost

2016/10/27

#
Nosson1459 wrote...
is there any method that checks if the the key was released
For a specific key, you will have to track its state. That is, add a boolean field to hold the last current state of the key:
// field for space key
private boolean spaceDown = false;

// in method
if (spaceDown != Greenfoot.isKeyDown("space")) // change in state?
{
    spaceDown = !spaceDown; // record change
    if (!spaceDown) // key released? (up after change in state)
    {
        // what to do when key is released
    }
}
Nosson1459 Nosson1459

2016/10/27

#
and after I shud make spaceDown back 2 false?
danpost danpost

2016/10/28

#
Nosson1459 wrote...
and after I shud make spaceDown back 2 false?
No. It will change, as is, when the key is pressed an when the key is released.
Nosson1459 Nosson1459

2016/10/28

#
thnx
You need to login to post a reply.