
When we release the key, the variable changes to false and the player stops moving. In other words: while the key is pressed, the variable is true and the player moves. If the variable is true, the program will change the player's position (note: 10 pixels per frame might be too much) every frame while this variable is true and it stays true until we trigger the KEYUP event. When we press the key, we trigger the KEYDOWN event which sets the variable to true.

Then check somewhere in your loop, whether the move_left or move_right variable is true: if move_right = True: In the event check of the loop you then handle them as follow: if event.type = KEYDOWN: You need to define a variable, for example "move_left" and "move_right".
#Soundplant key held down repeat code
It's always and everywhere like this, if you reinvent the wheel here, people can't read your code anymore. Then second: Change the x and y value, it's the wrong way round. (100) #What is this doing here?ĭISPLAYSURF.blit(player, (playerx, playery))

You don't need another module for that, but another approach and many more corrections are needed here.įirst of all: Do ONE blitting run per frame, not one everytime you changed something somewhere. I have tried adding a while loop, all that does is make the guys infinitetly go to the right/left, so is there a pygame module to add this? But how would I make it so when I hold the keys down, it repeats the the function, and if I let the keys go, it would stop. I have it so, when I press the right/left key the image goes left and right 10 pixels. (DISPLAYSURF, GRASSCOLOR, (0, 250, WINDOWWIDTH, 100)) Player = ('megaman_running_sprites_by_cobalt_blue_knight-d2y1i8s.png')ĭISPLAYSURF.blit(player, (playery, playerx))ĭef terminate(): # Terminates the program

DISPLAYSURF = _mode((WINDOWWIDTH, WINDOWHEIGHT))
