Making an image "walk"

Hello!

I am trying to implement the following: while participants listen to a piece of music, they need to tap the space bar following the rhythm. I would like to add an image that “walks” when participants tap the spacebar, otherwise it stays still.

I have added a code component at the beginning of the routine

x_pos = -0.45       
step = 0.05       
character_moving.pos = (x_pos, 0)

and at each frame:

keys = bar_character.getKeys(keyList=[‘space’], waitRelease=False)

if keys:
x_pos += step
x_pos = min(max(x_pos, -0.45), 0.45)
character_moving.pos = (x_pos, 0)

The problem is that my character does not proceed of one step at every key press, but I need to press multiple times before it moves ( as if the computer is not detecting the keypress, but I have checked multiple times and I do not get any error message). Changing the size of the steps does not help.

Do you have any ideas?

Thanks!

Is bar_charactet set to record all responses?

Hey!
This may be a silly answer, but where do you put .draw() and .flip()? That could be it

Since this is in the Builder category there probably shouldn’t be any flip commands, and draws may also not be relevant.

There is an automatic flip at the end of each frame.

It seems like the problem is with bar_character.If you don’t set getKeys to record all keys, it will only return keys once per frame. When you call getKeys, try adding clear=False so it doesn’t drop taps between frames. Also, make sure your routine’s frame rate is high enough to catch single taps. Also, make sure that the keyboard part is set to “force end of routine: no” so that it doesn’t miss the spacebar presses.