Pygame Tutorial - 6 - Keyboard Input Controls/ Key Pressed Event

preview_player
Показать описание
In this will video we learn to control the game using our Keyboard.

Next video - Adding Boundaries

#python #pygame
Рекомендации по теме
Комментарии
Автор

Indian guys giving programming tutorials on the internet should be heralded as heroes.

ldbonq
Автор

(this is also for people that want vertical movement)
For everybody who has problems with the character stopping after moving in the opposite direction:
Make 2 X and Y change variables, the first X_change is for left, the second for right, the first Y_change for down, the second for up.
And for PlayerX += change (for the movement to work), do PlayerX += X_change + X2_change, and the same for Y.

TheDurka
Автор

"and when we released the key, it is still moving. Why is that moving" hahaha cracked me up

javierbaguio
Автор

I love you my Indian brother you just helped me fix a bug

wolvAUS
Автор

Thx u 🙏 I have looked everywhere and finally I found a good tutorial on a pygame game, thanks again

Football-zone
Автор

Great video! I decided to go with a boolean value for both directions as I find it doesn't stop easily when switching directions quickly that the system you are using has. It's a bit more code, but I think it's worth it!

colbablast
Автор

This is really useful, thank you so mych>>

muntadher
Автор

my ship is not moving using the keyboard left or right ; but automatically moves itself when running the playerX +=0.1
portion of the code.

rhodakwoba
Автор

my ship is not moving and showing no errors

fictioncell
Автор

I got this type of error at 9:31


" playerX += playerX_change

NameError: name 'playerX_change' is not defined"

chandrakanthCK
Автор

hey there. thanks for the awesome tutorials. I'm trying to create some sort of ease-in-out smoothness. I'm not really sure how to achieve this. calling screen.blit() multiple times with different positions will just create multiple images of my player at different positions. i tried calling it twice with different x positions so that it moves a little faster. while it did move faster there were two of my player as i called screen.blit() twice. I'm not really sure how to go about this. or where i have to create some sort of loop to iterate different speeds. could you help me out here? much appreciated!!

revu
Автор

that movement algorithm have one problem :
if i hold left after hold right and now it start to go right when i remove my finger from left it stops(but normaly it must continue to go right) can we fix it ?

enestalhaylmaz
Автор

I am having an error in the player function as when I run the program everything runs fine but it displays the following:
DeprecationWarning: an integer is required (got type float). Implicit conversion to integers using __int__ is deprecated, and may be removed in a future version of Python.
screen.blit(playerimg, (x, y))
pls help

dsilvahome
Автор

Hello i have a problem when im trying use moving function i have to move always my mouse if i dont i have to click many times on right key

kvbksfl
Автор

How can I fix ghosting in the movement?

jonathanbloch
Автор

Left keystroke is working properly but right keystroke is not when i release it then ship doesnt stops same happens in y axis...why this i happening?

ritikasachan
Автор

great tutorial and explaination brother.. but you did some changes in the code and you didnt explain it and you keep changing the code.. when i try to understand it and you change again the code and its confusing me.. why not change the code at first?

ah-liew
Автор

Can you make a video on how to create a game menu

trashdude
Автор

I have a question: How do i stop Null-cancelling movement (I want to stop character from moving when opposing sides are pressed, i.e. left-right)

subject
Автор

the keystrokes aren't working and nothing is shown at the console :(

mixcraft