keyDown VS. keyWentDown

I cannot tell the difference between these two blocks (keyDown and keyWentDown)? I feel like they work the same in my project?

Can someone help explain?

Less 20 Mini Side Scroller

Hi @kbardelli,

The keyWentDown captures the instance the key was clicked. keyDown captures the an instance each time through the loop that the key is held down.

I tried to illustrate in this remix. If you hold the “w” key down which represents keyWentDown, the numbers only increment by one even if the key is held down. If you hold the “d” button which represents keyDown, the numbers increment each time through the loop for as long as the key is held down.

The game looks the same because once the velocity is set, the frog is jumping up and won’t come back down until the y value is triggered. It doesn’t matter if you trigger it once or repeatedly, once the velocity is set, the frog is on his way up.

I hope that makes helps.
~Michelle

1 Like

So, does it matter which one is used in this project? I think I understand but don’t know that it matters in this game.

Also, is there a way to only lose 1 health point when you touch the mushroom rather than a continuous countdown? The only way I think we learned is by hiding the mushroom or making it random.

I teach to test different conditions to make sure the outcome remains the same (clicking often to jump the frog, clicking just once). If the tests are the outcome the student wants, in my mind, I don’t think it matters which one you use (keyDown or keyWentDown).

For the health to only decrease by one, there are a few methods outlined in this really informational post (find josh’s response). The easiest way by far is to move the mushroom’s position so that the sprites are no longer touching but there are other ways outlined in the post. FYI - hiding the mushroom (or making it invisible) won’t work but hiding its position (an x position off the screen) would work. In this game, I would just quickly move it an x position that allows it to skip over the frog. Good luck!

~Michelle

I just played with it! I agree, moving the x position seems to be the easiest!
Thanks!